Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.

The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to *n*. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 → 2 → 4 → 5. 

In one second, you can perform one of the two following operations:
 -  Having a matryoshka *a* that isn't nested in any other matryoshka and a matryoshka *b*, such that *b* doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put *a* in *b*; -  Having a matryoshka *a* directly contained in matryoshka *b*, such that *b* is not nested in any other matryoshka, you may get *a* out of *b*. 
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 → 2 → ... → *n*). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
The first line contains integers *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>) and *k* (1 ≤ *k* ≤ 10<sup class="upper-index">5</sup>) — the number of matryoshkas and matryoshka chains in the initial configuration.

The next *k* lines contain the descriptions of the chains: the *i*-th line first contains number *m*<sub class="lower-index">*i*</sub> (1 ≤ *m*<sub class="lower-index">*i*</sub> ≤ *n*), and then *m*<sub class="lower-index">*i*</sub> numbers *a*<sub class="lower-index">*i*1</sub>, *a*<sub class="lower-index">*i*2</sub>, ..., *a*<sub class="lower-index">*im*<sub class="lower-index">*i*</sub></sub> — the numbers of matryoshkas in the chain (matryoshka *a*<sub class="lower-index">*i*1</sub> is nested into matryoshka *a*<sub class="lower-index">*i*2</sub>, that is nested into matryoshka *a*<sub class="lower-index">*i*3</sub>, and so on till the matryoshka *a*<sub class="lower-index">*im*<sub class="lower-index">*i*</sub></sub> that isn't nested into any other matryoshka).

It is guaranteed that *m*<sub class="lower-index">1</sub> + *m*<sub class="lower-index">2</sub> + ... + *m*<sub class="lower-index">*k*</sub> = *n*, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<double,double> dd;
typedef pair<ll,ll> pll;
typedef pair<string,int> psi;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<ii> > vvip;
typedef vector<ii> vii;
typedef map<int,int> mpi;
#define pb push_back
#define F first
#define S second
#define MOD 1000000007
#define NA -1
#define ALL(v) v.begin(),v.end()
#define mp make_pair
#define rep(i, n) for (int (i) = 0; (i) < (n); (i) ++)
#define rep1(i, n) for (int (i) = 1; (i) <= (n); (i) ++)
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout<<#a<<" :";FOR(i123,x,y)cout<<setw(4)<<(a)[i123];cout<<endl;}
#define foreach(e, x) for (__typeof(x.begin()) e = x.begin(); e != x.end(); e++) 
#define clr(x) memset(x,0,sizeof(x));
#define sz(x) int((x).size())
#define endl '\n'
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
#define sc(t) scanf("%d",&t)
// vector<string> split(const string &s, char delim) {
//     stringstream ss(s);
//     string item;
//     vector<string> tokens;
//     while (getline(ss, item, delim)) {
//         tokens.push_back(item);
//     }
//     return tokens;
// }
typedef pair<pll,ll> ppll;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
#define re return
ll gcd(ll x,ll y){ re y==0?x:gcd(y,x%y);}
int a[1000000],ct[1000000];

int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	//     freopen("output.txt","w",stdout);;
	// #endif
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	//ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0);
	int n,k;
	cin>>n>>k;
	clr(a);
	clr(ct);
	rep(i,k)
	{
		int nk;
		cin>>nk;
		rep(j,nk)
		{
			int x;
			cin>>x;
			a[x]=i;
			ct[i]++;
		}
	}
	int ans=0;
	for(int i=1;i<=n-1;i++)
	{
		if(a[i]==a[i+1])
		{

			ct[a[i]]--;
			continue;
		}
		else
		{
			if(ct[a[i]]>1)
			{
				ct[a[i]]--;
				ans++;
			}
			ans++;	
		}
	}
	cout<<ans<<endl;
	re 0;
} 
