#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define range(i,a,b) for(int i = (a);i <= (b);i++)
#define rrep(i,n) for(int i = (n);i >= 0;i--)
#define rran(i,a,b) for(int i = (b);i >= (a);i--)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define MAX 110000
using namespace std;

typedef vector<int> vi;

vi chains[MAX];
int end[MAX],C[MAX];

void decompose(vi & V){
	int cost = 0;
	for(int i = 0;i < V.size();){
		int j = i + 1;
		while(j < V.size() && V[j] == V[j - 1] + 1) j++;
		C[V[i]] = cost;
		end[V[i]] = V[j - 1];		
		i = j;
		if(!cost) cost++;
	}
}

int main(){
	int n,k,m;
	scanf("%d %d",&n,&k);
	loop(i,k){
		scanf("%d",&m);
		chains[i] = vi(m);
		loop(j,m) scanf("%d",&chains[i][j]);
		decompose(chains[i]);
	} 
	int s = 1; long long ans = 0;
	while(s <= n){
		ans += C[s] + 1;
		s = end[s] + 1;
	}
	--ans;
	cout << ans << endl;
	return 0;
}
