题目传送门
/*
题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步
贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0),先从1开始找到已经套好的娃娃层数,
其他是2次操作,还要减去k-1个娃娃是只要套上就可以
详细解释:http://blog.csdn.net/firstlucker/article/details/46671251
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int main(void) //Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
{
// freopen ("C.in", "r", stdin);
int n, k;
while (scanf ("%d%d", &n, &k) == )
{
int cnt = ;
for (int i=; i<=k; ++i)
{
int m; scanf ("%d", &m); int p = ;
for (int j=; j<=m; ++j)
{
scanf ("%d", &a[j]); if (a[j] == ) p = j;
}
if (p)
{
for (int j=p+; j<=m; ++j)
{
if (a[j] == a[j-] + ) cnt++;
else break;
}
}
}
printf ("%d\n", (n - - cnt) * - (k - ));
}
return ;
}