#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair <ll, ll> pll;

const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const ll Inf = 1LL << 62;

int ar[7] = {0, 4, 8, 15, 16, 23, 42};
int mp[Max];
int ans[Max];

int main() {
#ifdef Mr_Emrul
	freopen("inputf.in", "r", stdin);
#endif /// Mr_Emrul

	set <int> A;
	for(int i = 1; i <= 6; i++) {
		A.insert(ar[i]);
	}
	int x, y, a, b;
	cout << "? 2 1" << endl;
	fflush(stdout);
	cin >> x;
	cout << "? 2 3" << endl;
	fflush(stdout);
	cin >> y;
	cout << "? 5 4" << endl;
	fflush(stdout);
	cin >> a;
	cout << "? 5 6" << endl;
	fflush(stdout);
	cin >> b;
	for(int i = 1; i <= 6; i++) {
		for(int j = 1; j <= 6; j++) {
			if(i == j) {
				continue;
			}
			ans[2] = ar[i];
			ans[1] = x / ar[i]; if(ans[1] * ar[i] != x) continue;
			ans[3] = y / ar[i];
			if(ans[3] * ar[i] != y) continue;
			ans[5] = ar[j];
			ans[4] = a / ar[j];
			if(ans[4] * ar[j] != a) continue;
			ans[6] = b / ar[j];
			if(ans[6] * ar[j] != b) continue;
			set <int> B;
			for(int l = 1; l <= 6; l++) {
				B.insert(ans[l]);
			}
			if(A == B) {
				printf("!");
				fflush(stdout);
				for(int i = 1; i <= 6; i++) {
					printf(" %d", ans[i]);
					fflush(stdout);
				}
				printf("\n");
				fflush(stdout);
				return 0;
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
//#define int long long int
using namespace std;
int ok = 1000*1000*1000+7;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi  pair<int,int>

int a[6]={4,8,5,16,23,42};
int b[6];
int p=0;
map<int,pi>mp;
int h[50];

signed main(){
	fast;
	int n,m;
	for(int i=0;i<6;i++){
		for(int j=0;j<6;j++){

			 mp.insert( { a[i]*a[j] , {a[i],a[j]} } );
		}
	}
	 cout << "? " << 1 << " " << 1 << endl<<  flush;

	scanf("%d\n",&n);

	int x=sqrt(n);
	b[p++]=sqrt(n);
	h[x]=1;

	cout << "? " << 2 << " " << 2 << endl<<  flush;

	scanf("%d\n",&n);

	b[p++]=sqrt(n);
	 x=sqrt(n);
	h[x]=1;

	cout << "? " << 3 << " " << 4 << endl<<  flush;

	scanf("%d\n",&n);

	cout << "? " << 4 << " " << 5 << endl<<  flush;

	scanf("%d\n",&m);
	pi q = mp[n];
	pi qq = mp[m];
	if(q.first==qq.first||qq.second==q.first){
		b[2]=q.second;
		h[q.second]=1;

		b[3]=q.first;
		h[q.first]=1;

		b[4]=m/q.first;
		h[m/q.first]=1;
	}
	if(q.second==qq.first||qq.second==q.second){
		b[2]=n/q.second;
		b[3]=q.second;
		b[4]=m/q.second;
		h[n/q.second]=1;
		h[q.second]=1;
		h[m/q.second]=1;
	}
	for(int i=0;i<6;i++){
		if(h[a[i]]!=1)b[5]=a[i];
	}
	printf("! %d %d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4],a[5]);

	fflush(stdout);

}


#include <bits/stdc++.h>
//#define int long long int
using namespace std;
int ok = 1000*1000*1000+7;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi  pair<int,int>

int a[6]={4,8,5,16,23,42};
int b[6];
int p=0;
map<int,pi>mp;
int h[50];

signed main(){
	fast;
	int n,m;
	for(int i=0;i<6;i++){
		for(int j=0;j<6;j++){

			 mp.insert( { a[i]*a[j] , {a[i],a[j]} } );
		}
	}
	 cout << "? " << 1 << " " << 1 << endl<<  flush;

	scanf("%d\n",&n);

	int x=sqrt(n);
	b[p++]=sqrt(n);
	h[x]=1;

	cout << "? " << 2 << " " << 2 << endl<<  flush;

	scanf("%d\n",&n);

	b[p++]=sqrt(n);
	 x=sqrt(n);
	h[x]=1;

	cout << "? " << 3 << " " << 4 << endl<<  flush;

	scanf("%d\n",&n);

	cout << "? " << 4 << " " << 5 << endl<<  flush;

	scanf("%d\n",&m);
	pi q = mp[n];
	pi qq = mp[m];
	if(q.first==qq.first||qq.second==q.first){
		b[2]=q.second;
		h[q.second]=1;

		b[3]=q.first;
		h[q.first]=1;

		b[4]=m/q.first;
		h[m/q.first]=1;
	}
	if(q.second==qq.first||qq.second==q.second){
		b[2]=n/q.second;
		b[3]=q.second;
		b[4]=m/q.second;
		h[n/q.second]=1;
		h[q.second]=1;
		h[m/q.second]=1;
	}
	for(int i=0;i<6;i++){
		if(h[a[i]]!=1)b[5]=a[i];
	}
	//printf("! %d %d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4],a[5]);
	cout<<"! "<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<" "<<a[5]<<endl<<flush;

}


#include <bits/stdc++.h>
//#define int long long int
using namespace std;
int ok = 1000*1000*1000+7;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi  pair<int,int>

int a[6]={4,8,5,16,23,42};
int b[6];
int p=0;
map<int,pi>mp;
int h[50];

signed main(){
	fast;
	int n,m,s,d;
	for(int i=0;i<6;i++){
		for(int j=0;j<6;j++){

			 mp.insert( { a[i]*a[j] , {a[i],a[j]} } );
		}
	}
	cout << "? " << 1 << " " << 1 << endl<<  flush;

	cin>>n;
	cout << "? " << 2 << " " << 2 << endl<<  flush;

	cin>>m;
	cout << "? " << 3 << " " << 4 << endl<<  flush;

	cin>>s;
	cout << "? " << 4 << " " << 5 << endl<<  flush;

	cin>>d;

	int x=sqrt(n);
	b[p++]=sqrt(n);
	h[x]=1;

	b[p++]=sqrt(m);
	 x=sqrt(m);
	h[x]=1;

	scanf("%d\n",&m);
	pi q = mp[s];
	pi qq = mp[d];
	if(q.first==qq.first||qq.second==q.first){
		b[2]=q.second;
		h[q.second]=1;

		b[3]=q.first;
		h[q.first]=1;

		b[4]=m/q.first;
		h[m/q.first]=1;
	}
	if(q.second==qq.first||qq.second==q.second){
		b[2]=n/q.second;
		b[3]=q.second;
		b[4]=m/q.second;
		h[n/q.second]=1;
		h[q.second]=1;
		h[m/q.second]=1;
	}
	for(int i=0;i<6;i++){
		if(h[a[i]]!=1)b[5]=a[i];
	}
	//printf("! %d %d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4],a[5]);
	cout<<"! "<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<" "<<a[5]<<endl<<flush;

}


#include <bits/stdc++.h>
#define int long long int
using namespace std;
int ok = 1000*1000*1000+7;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi  pair<int,int>

int a[6]={4,8,5,16,23,42};
int b[6];
int p=0;
map<int,pi>mp;
int h[50];

signed main(){
	fast;
	int n,m;
	for(int i=0;i<6;i++){
		for(int j=0;j<6;j++){
			//m[a[i]*a[j]]={a[i],a[j]};
			 mp.insert( { a[i]*a[j] , {a[i],a[j]} } );
		}
	}
	cout<<"? 1 1\n";
	fflush(stdout);
	cin>>n;

	int x=sqrt(n);
	b[p++]=sqrt(n);
	h[x]=1;

	cout<<"? 2 2\n";
	fflush(stdout);
	cin>>n;

	b[p++]=sqrt(n);
	 x=sqrt(n);
	h[x]=1;

	cout<<"? 3 4\n";
	fflush(stdout);
	cin>>n;

	cout<<"? 4 5\n";
	fflush(stdout);
	cin>>m;
	pi q = mp[n];
	pi qq = mp[m];
	if(q.first==qq.first||qq.second==q.first){
		b[2]=q.second;
		h[q.second]=1;

		b[3]=q.first;
		h[q.first]=1;

		b[4]=m/q.first;
		h[m/q.first]=1;
	}
	if(q.second==qq.first||qq.second==q.second){
		b[2]=n/q.second;
		b[3]=q.second;
		b[4]=m/q.second;
		h[n/q.second]=1;
		h[q.second]=1;
		h[m/q.second]=1;
	}
	for(int i=0;i<6;i++){
		if(h[a[i]]!=1)b[5]=a[i];
	}
	cout<<"! "<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<" "<<a[5]<<"\n";
	fflush(stdout);

}


#include <bits/stdc++.h>
//#define int long long int
using namespace std;
int ok = 1000*1000*1000+7;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi  pair<int,int>

signed main(){
int a[6]={4,8,15,16,23,42};
int b[6];

map<int,pi>mp;
int h[50];
memset(h,0,sizeof(h));

	fast;
	int n,m,s,d;
	for(int i=0;i<6;i++){
		for(int j=0;j<6;j++){
			pi oo = {a[i],a[j]};
			 mp[a[i]*a[j]] = oo;
			}

		}

	cout << "? " << 1 << " " << 1 << endl<<  flush;

	cin>>n;
	cout << "? " << 2 << " " << 2 << endl<<  flush;

	cin>>m;
	cout << "? " << 3 << " " << 4 << endl<<  flush;

	cin>>s;
	cout << "? " << 4 << " " << 5 << endl<<  flush;

	cin>>d;

	int x=sqrt(n);
	b[0]=sqrt(n);
	h[x]=1;

	b[1]=sqrt(m);
	 x=sqrt(m);
	h[x]=1;

	pi q = mp[s];
	pi qq = mp[d];

	if(q.first==qq.first||qq.second==q.first){
		b[2]=s/q.first;
		h[s/q.first]=1;

		b[3]=q.first;
		h[q.first]=1;

		b[4]=d/q.first;
		h[d/q.first]=1;
	}
	else if(q.second==qq.first||qq.second==q.second){
		b[2]=s/q.second;
		b[3]=q.second;
		b[4]=d/q.second;
		h[s/q.second]=1;
		h[q.second]=1;
		h[d/q.second]=1;
	}

	for(int i=0;i<6;i++){
		if(h[a[i]]!=1)b[5]=a[i];
	}

	cout<<"! "<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<" "<<a[5]<<endl<<flush;

}


#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

#define spc        printf(" ")
#define nln        puts("")                         ///printnewline
#define Max(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define Min(a,b,c) min(a,min(b,c))                  ///3 ta theke min
#define sqr(x)     (x)*(x)

#define z(x)       fabs(x)<EPS
#define iqu(x,y)   z(fabs(x-y))

#define rep(i,a,b)  for(i=a;i<=b;i++)
#define rep0(i,n)   for(i=0;i<n;i++)
#define rep1(i,n)   for(i=1;i<=n;i++)               ///looping
#define rev(i,a,b)  for(i=a;i>=b;i--)
#define rev0(i,n)   for(i=n-1;i>=0;i--)
#define rev1(i,n)   for(i=n;i>=1;i--)
#define forstl(i,v) for(i=0;i<v.size();i++)
#define forit(it,v)    for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(p)      p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define vi         vector<int>
#define vll        vector<long long>
#define vs         vector<string>
#define pii        pair<int,int>
#define pll        pair<long long,long long>
#define sz(c)      (int)c.size()
#define pb(x)      push_back(x)                     ///STL defines
#define mp(x,y)    make_pair(x,y)
#define xx         first
#define yy         second
#define _itr(v)    __typeof(v.begin())

#define LLI        long long int
#define i64        long long int
#define i64u       unsigned long long int
#define LLU        unsigned long long int
#define Double     long double
#define PI         acos(-1.0)                        ///PI er value

#define check(n, pos)  (bool)(n & (1LL<<(pos)))      ///CHECK
#define biton(n, pos)  (n | (1LL<<(pos)))            ///ON     }-bit opr.
#define bitoff(n, pos) (n & ~(1LL<<(pos)))           ///OFF

// reading and writing case
#define readcase  int cas,kase=0;CI(cas);while((cas--)&&(++kase))
#define printcase printf("Case %d:",kase)

//debugging infinite variable
bool deb_mode = 0;
#define debug(a...)     if(deb_mode){cout<<"Line= "<<__LINE__<<" -> ";Dbug,a,#a;Dbug.printall();cout<<endl;}
class debugger {
    vector<string> vars;
public:
    template<typename T> debugger& operator , ( const T v ) { stringstream ss; ss << v, vars.push_back( ss.str() ); return *this; }
    void printall() { int j = 0, l = vars.size(); for( int i = 0; i < ( l - 1 ); i++ ) { if( i )cout << ", "; for( j; j < vars[l - 1].size(); j++ ) { if( vars[l - 1][j] == ',' ) {j++; break;} cout << vars[l - 1][j]; } cout << " = " << vars[i]; } vars.clear(); }
} Dbug;

///STL printing output stream overloading
template <typename T1, typename T2> inline ostream& operator << ( ostream& os, const pair<T1, T2>& p ) { return os << "(" << p.first << "," << p.second << ")"; }
template <typename T> inline ostream &operator << ( ostream & os, const vector<T>& v ) { bool first = true; os << "{"; for( unsigned int i = 0; i < v.size(); i++ ) { if( !first ) os << ","; os << v[i]; first = false; } return os << "}"; }
template <typename T> inline ostream &operator << (  ostream & os, const set<T>& v ) { bool first = true; os << "{"; for ( typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii; first = false; } return os << "}"; }
template <typename T1, typename T2> inline ostream &operator << ( ostream & os, const map<T1, T2>& v ) { bool first = true; os << "{"; for ( typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii ; first = false; } return os << "}"; }

template <typename T> void getarray( T a[], int b, int e ) { for( int i = b; i < e + b; i++ ) cin >> a[i]; }
template <typename T> void printarray( T a[], int b, int e ) { for( int i = b; i < e - 1 + b; i++ ) cout << a[i] << " "; if( e - 1 + b >= 0 ) cout << a[e - 1 + b] << endl; }
template <typename T> void printV( vector<T> v ) { int sz = v.size(); if( sz ) cout << v[0]; for( int i = 1; i < sz; i++ ) cout << " " << v[i]; nln; }

template <typename T> T gcd( T a, T b ) { if( b == 0 ) return a; return gcd( b, a % b ); }
template <typename T> T BigMod ( T b, T p, T m ) { if ( p == 0 ) return 1; if ( p % 2 == 0 ) { T s = BigMod( b, p / 2, m ); return ( ( s % m ) * ( s % m ) ) % m; } return ( ( b % m ) * ( BigMod( b, p - 1, m ) % m ) ) % m; }
template <typename T> T ModInv ( T b, T m ) { return BigMod( b, m - 2, m ); }

template<class T> inline void read( T &x ) { bool Minus = 0; char c; for( c = getchar(); c <= 32; c = getchar() ) ; if( c == '-' ) Minus = 1, c = getchar(); for( x = 0; c > 32; c = getchar() ) x = x * 10 + c - '0'; if( Minus ) x = -x; }
char getc() { char c; for( c = getchar(); c <= 32; c = getchar() ); return c; }  ///input char with buffering
int CI( int &_x ) { return scanf( "%d", &_x ); }
int CI( int &_x, int &_y ) { return scanf( "%d %d", &_x, &_y ); }
int CI( int &_x, int &_y, int &_z ) { return scanf( "%d %d %d", &_x, &_y, &_z ); }
int CI( int &_a, int &_b, int &_c, int &_d ) { return scanf( "%d %d %d %d", &_a, &_b, &_c, &_d ); }

template <class T> string toString( T n ) { ostringstream oss; oss << n; return oss.str(); }
int toInt( string s ) { int r = 0; istringstream sin( s ); sin >> r; return r; }
i64 toLong( string s ) { i64 r = 0; istringstream sin( s ); sin >> r; return r; }
bool isVowel( char ch ) { ch = tolower( ch ); if( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )return true; return false; }
bool isUpper( char c ) { return c >= 'A' && c <= 'Z'; }
bool isLower( char c ) { return c >= 'a' && c <= 'z'; }

int dr8[8] = { +1, -1, +0, +0, +1, -1, -1, +1};   ///8 direction move
int dc8[8] = { +0, +0, -1, +1, +1, +1, -1, -1};
int dr4[4] = { +0, +0, +1, -1};                   ///4 direction move
int dc4[4] = { -1, +1, +0, +0};                   ///or adjacent dir.
int kn8r[8] = { +1, +2, +2, +1, -1, -2, -2, -1};  ///knight moves
int kn8c[8] = { +2, +1, -1, -2, -2, -1, +1, +2};

const double EPS = 1e-9;                         ///constants
const int INF = ( 1 << 30 ) - 1;
const i64 LINF = ( 1ll << 62 ) - 1;
const int mod = ( int )1e9 + 7;
const int MAX = ( int )1e5;
///____________________________Main Coding Starts From Here________________________///

vector< vector<int> > segments;

int main() {
#ifndef ONLINE_JUDGE
//    READ("in.txt");
//    WRITE("out.txt");
    deb_mode = 1;
#endif
    if( deb_mode )
        srand( int( time( NULL ) ) );

    int i, j, k, l, n, m, q, a, b, c;
    CI( n, m );
    i64 ans = 0;
    rep1( i, m ) {
        vector<int> nowChain;
        CI( q );
        rep1( j, q ) {
            CI( a );
            if( nowChain.size() == 0 ) {
                nowChain.pb( a );
            }
            else {
                if( nowChain.back() + 1 == a ) {
                    nowChain.pb( a );
                }
                else {
                    ans++;
                    segments.pb( nowChain );
                    nowChain.clear();
                    nowChain.pb( a );
                }
            }
        }
        if( nowChain.size() != 0 )
            segments.pb( nowChain );
        nowChain.clear();
    }

//debug(segments);
    cout << ans + segments.size() - 1 << "\n";

    if( deb_mode )
        cerr << "TIME = " << clock() << " ms" << endl;
    return 0;
}


#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

#define spc        printf(" ")
#define nln        puts("")                         ///printnewline
#define Max(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define Min(a,b,c) min(a,min(b,c))                  ///3 ta theke min
#define sqr(x)     (x)*(x)

#define z(x)       fabs(x)<EPS
#define iqu(x,y)   z(fabs(x-y))

#define rep(i,a,b)  for(i=a;i<=b;i++)
#define rep0(i,n)   for(i=0;i<n;i++)
#define rep1(i,n)   for(i=1;i<=n;i++)               ///looping
#define rev(i,a,b)  for(i=a;i>=b;i--)
#define rev0(i,n)   for(i=n-1;i>=0;i--)
#define rev1(i,n)   for(i=n;i>=1;i--)
#define forstl(i,v) for(i=0;i<v.size();i++)
#define forit(it,v)    for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(p)      p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define vi         vector<int>
#define vll        vector<long long>
#define vs         vector<string>
#define pii        pair<int,int>
#define pll        pair<long long,long long>
#define sz(c)      (int)c.size()
#define pb(x)      push_back(x)                     ///STL defines
#define mp(x,y)    make_pair(x,y)
#define xx         first
#define yy         second
#define _itr(v)    __typeof(v.begin())

#define LLI        long long int
#define i64        long long int
#define i64u       unsigned long long int
#define LLU        unsigned long long int
#define Double     long double
#define PI         acos(-1.0)                        ///PI er value

#define check(n, pos)  (bool)(n & (1LL<<(pos)))      ///CHECK
#define biton(n, pos)  (n | (1LL<<(pos)))            ///ON     }-bit opr.
#define bitoff(n, pos) (n & ~(1LL<<(pos)))           ///OFF

// reading and writing case
#define readcase  int cas,kase=0;CI(cas);while((cas--)&&(++kase))
#define printcase printf("Case %d:",kase)

//debugging infinite variable
bool deb_mode = 0;
#define debug(a...)     if(deb_mode){cout<<"Line= "<<__LINE__<<" -> ";Dbug,a,#a;Dbug.printall();cout<<endl;}
class debugger {
    vector<string> vars;
public:
    template<typename T> debugger& operator , ( const T v ) { stringstream ss; ss << v, vars.push_back( ss.str() ); return *this; }
    void printall() { int j = 0, l = vars.size(); for( int i = 0; i < ( l - 1 ); i++ ) { if( i )cout << ", "; for( j; j < vars[l - 1].size(); j++ ) { if( vars[l - 1][j] == ',' ) {j++; break;} cout << vars[l - 1][j]; } cout << " = " << vars[i]; } vars.clear(); }
} Dbug;

///STL printing output stream overloading
template <typename T1, typename T2> inline ostream& operator << ( ostream& os, const pair<T1, T2>& p ) { return os << "(" << p.first << "," << p.second << ")"; }
template <typename T> inline ostream &operator << ( ostream & os, const vector<T>& v ) { bool first = true; os << "{"; for( unsigned int i = 0; i < v.size(); i++ ) { if( !first ) os << ","; os << v[i]; first = false; } return os << "}"; }
template <typename T> inline ostream &operator << (  ostream & os, const set<T>& v ) { bool first = true; os << "{"; for ( typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii; first = false; } return os << "}"; }
template <typename T1, typename T2> inline ostream &operator << ( ostream & os, const map<T1, T2>& v ) { bool first = true; os << "{"; for ( typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii ; first = false; } return os << "}"; }

template <typename T> void getarray( T a[], int b, int e ) { for( int i = b; i < e + b; i++ ) cin >> a[i]; }
template <typename T> void printarray( T a[], int b, int e ) { for( int i = b; i < e - 1 + b; i++ ) cout << a[i] << " "; if( e - 1 + b >= 0 ) cout << a[e - 1 + b] << endl; }
template <typename T> void printV( vector<T> v ) { int sz = v.size(); if( sz ) cout << v[0]; for( int i = 1; i < sz; i++ ) cout << " " << v[i]; nln; }

template <typename T> T gcd( T a, T b ) { if( b == 0 ) return a; return gcd( b, a % b ); }
template <typename T> T BigMod ( T b, T p, T m ) { if ( p == 0 ) return 1; if ( p % 2 == 0 ) { T s = BigMod( b, p / 2, m ); return ( ( s % m ) * ( s % m ) ) % m; } return ( ( b % m ) * ( BigMod( b, p - 1, m ) % m ) ) % m; }
template <typename T> T ModInv ( T b, T m ) { return BigMod( b, m - 2, m ); }

template<class T> inline void read( T &x ) { bool Minus = 0; char c; for( c = getchar(); c <= 32; c = getchar() ) ; if( c == '-' ) Minus = 1, c = getchar(); for( x = 0; c > 32; c = getchar() ) x = x * 10 + c - '0'; if( Minus ) x = -x; }
char getc() { char c; for( c = getchar(); c <= 32; c = getchar() ); return c; }  ///input char with buffering
int CI( int &_x ) { return scanf( "%d", &_x ); }
int CI( int &_x, int &_y ) { return scanf( "%d %d", &_x, &_y ); }
int CI( int &_x, int &_y, int &_z ) { return scanf( "%d %d %d", &_x, &_y, &_z ); }
int CI( int &_a, int &_b, int &_c, int &_d ) { return scanf( "%d %d %d %d", &_a, &_b, &_c, &_d ); }

template <class T> string toString( T n ) { ostringstream oss; oss << n; return oss.str(); }
int toInt( string s ) { int r = 0; istringstream sin( s ); sin >> r; return r; }
i64 toLong( string s ) { i64 r = 0; istringstream sin( s ); sin >> r; return r; }
bool isVowel( char ch ) { ch = tolower( ch ); if( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )return true; return false; }
bool isUpper( char c ) { return c >= 'A' && c <= 'Z'; }
bool isLower( char c ) { return c >= 'a' && c <= 'z'; }

int dr8[8] = { +1, -1, +0, +0, +1, -1, -1, +1};   ///8 direction move
int dc8[8] = { +0, +0, -1, +1, +1, +1, -1, -1};
int dr4[4] = { +0, +0, +1, -1};                   ///4 direction move
int dc4[4] = { -1, +1, +0, +0};                   ///or adjacent dir.
int kn8r[8] = { +1, +2, +2, +1, -1, -2, -2, -1};  ///knight moves
int kn8c[8] = { +2, +1, -1, -2, -2, -1, +1, +2};

const double EPS = 1e-9;                         ///constants
const int INF = ( 1 << 30 ) - 1;
const i64 LINF = ( 1ll << 62 ) - 1;
const int mod = ( int )1e9 + 7;
const int MAX = ( int )1e5;
///____________________________Main Coding Starts From Here________________________///

vector< vector<int> > segments;

int main() {
#ifndef ONLINE_JUDGE
//    READ("in.txt");
//    WRITE("out.txt");
    deb_mode = 1;
#endif
    if( deb_mode )
        srand( int( time( NULL ) ) );

    int i, j, k, l, n, m, q, a, b, c;
    CI( n, m );
    i64 ans = 0;
    int firstSegmentIndex = -1;
    rep1( i, m ) {
        vector<int> nowChain;
        CI( q );
        rep1( j, q ) {
            CI( a );
            if( a == 1 ) {
                firstSegmentIndex = j - 1;
            }
            if( nowChain.size() == 0 ) {
                nowChain.pb( a );
            }
            else {
                if( nowChain.back() + 1 == a ) {
                    nowChain.pb( a );
                }
                else {
                    ans++;
                    segments.pb( nowChain );
                    nowChain.clear();
                    nowChain.pb( a );
                }
            }
        }
        if( nowChain.size() != 0 )
            segments.pb( nowChain );
        nowChain.clear();
    }

    //debug( ans );
    //debug( segments );
    for( i = 0; i < segments.size(); i++ ) {
        if( i == firstSegmentIndex )continue;
        ans += segments[i].size();
        ans += segments[i].size() - 1;
    }

    cout << ans << "\n";

    if( deb_mode )
        cerr << "TIME = " << clock() << " ms" << endl;
    return 0;
}


#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

#define spc        printf(" ")
#define nln        puts("")                         ///printnewline
#define Max(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define Min(a,b,c) min(a,min(b,c))                  ///3 ta theke min
#define sqr(x)     (x)*(x)

#define z(x)       fabs(x)<EPS
#define iqu(x,y)   z(fabs(x-y))

#define rep(i,a,b)  for(i=a;i<=b;i++)
#define rep0(i,n)   for(i=0;i<n;i++)
#define rep1(i,n)   for(i=1;i<=n;i++)               ///looping
#define rev(i,a,b)  for(i=a;i>=b;i--)
#define rev0(i,n)   for(i=n-1;i>=0;i--)
#define rev1(i,n)   for(i=n;i>=1;i--)
#define forstl(i,v) for(i=0;i<v.size();i++)
#define forit(it,v)    for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(p)      p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define vi         vector<int>
#define vll        vector<long long>
#define vs         vector<string>
#define pii        pair<int,int>
#define pll        pair<long long,long long>
#define sz(c)      (int)c.size()
#define pb(x)      push_back(x)                     ///STL defines
#define mp(x,y)    make_pair(x,y)
#define xx         first
#define yy         second
#define _itr(v)    __typeof(v.begin())

#define LLI        long long int
#define i64        long long int
#define i64u       unsigned long long int
#define LLU        unsigned long long int
#define Double     long double
#define PI         acos(-1.0)                        ///PI er value

#define check(n, pos)  (bool)(n & (1LL<<(pos)))      ///CHECK
#define biton(n, pos)  (n | (1LL<<(pos)))            ///ON     }-bit opr.
#define bitoff(n, pos) (n & ~(1LL<<(pos)))           ///OFF

// reading and writing case
#define readcase  int cas,kase=0;CI(cas);while((cas--)&&(++kase))
#define printcase printf("Case %d:",kase)

//debugging infinite variable
bool deb_mode = 0;
#define debug(a...)     if(deb_mode){cout<<"Line= "<<__LINE__<<" -> ";Dbug,a,#a;Dbug.printall();cout<<endl;}
class debugger {
    vector<string> vars;
public:
    template<typename T> debugger& operator , ( const T v ) { stringstream ss; ss << v, vars.push_back( ss.str() ); return *this; }
    void printall() { int j = 0, l = vars.size(); for( int i = 0; i < ( l - 1 ); i++ ) { if( i )cout << ", "; for( j; j < vars[l - 1].size(); j++ ) { if( vars[l - 1][j] == ',' ) {j++; break;} cout << vars[l - 1][j]; } cout << " = " << vars[i]; } vars.clear(); }
} Dbug;

///STL printing output stream overloading
template <typename T1, typename T2> inline ostream& operator << ( ostream& os, const pair<T1, T2>& p ) { return os << "(" << p.first << "," << p.second << ")"; }
template <typename T> inline ostream &operator << ( ostream & os, const vector<T>& v ) { bool first = true; os << "{"; for( unsigned int i = 0; i < v.size(); i++ ) { if( !first ) os << ","; os << v[i]; first = false; } return os << "}"; }
template <typename T> inline ostream &operator << (  ostream & os, const set<T>& v ) { bool first = true; os << "{"; for ( typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii; first = false; } return os << "}"; }
template <typename T1, typename T2> inline ostream &operator << ( ostream & os, const map<T1, T2>& v ) { bool first = true; os << "{"; for ( typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii ; first = false; } return os << "}"; }

template <typename T> void getarray( T a[], int b, int e ) { for( int i = b; i < e + b; i++ ) cin >> a[i]; }
template <typename T> void printarray( T a[], int b, int e ) { for( int i = b; i < e - 1 + b; i++ ) cout << a[i] << " "; if( e - 1 + b >= 0 ) cout << a[e - 1 + b] << endl; }
template <typename T> void printV( vector<T> v ) { int sz = v.size(); if( sz ) cout << v[0]; for( int i = 1; i < sz; i++ ) cout << " " << v[i]; nln; }

template <typename T> T gcd( T a, T b ) { if( b == 0 ) return a; return gcd( b, a % b ); }
template <typename T> T BigMod ( T b, T p, T m ) { if ( p == 0 ) return 1; if ( p % 2 == 0 ) { T s = BigMod( b, p / 2, m ); return ( ( s % m ) * ( s % m ) ) % m; } return ( ( b % m ) * ( BigMod( b, p - 1, m ) % m ) ) % m; }
template <typename T> T ModInv ( T b, T m ) { return BigMod( b, m - 2, m ); }

template<class T> inline void read( T &x ) { bool Minus = 0; char c; for( c = getchar(); c <= 32; c = getchar() ) ; if( c == '-' ) Minus = 1, c = getchar(); for( x = 0; c > 32; c = getchar() ) x = x * 10 + c - '0'; if( Minus ) x = -x; }
char getc() { char c; for( c = getchar(); c <= 32; c = getchar() ); return c; }  ///input char with buffering
int CI( int &_x ) { return scanf( "%d", &_x ); }
int CI( int &_x, int &_y ) { return scanf( "%d %d", &_x, &_y ); }
int CI( int &_x, int &_y, int &_z ) { return scanf( "%d %d %d", &_x, &_y, &_z ); }
int CI( int &_a, int &_b, int &_c, int &_d ) { return scanf( "%d %d %d %d", &_a, &_b, &_c, &_d ); }

template <class T> string toString( T n ) { ostringstream oss; oss << n; return oss.str(); }
int toInt( string s ) { int r = 0; istringstream sin( s ); sin >> r; return r; }
i64 toLong( string s ) { i64 r = 0; istringstream sin( s ); sin >> r; return r; }
bool isVowel( char ch ) { ch = tolower( ch ); if( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )return true; return false; }
bool isUpper( char c ) { return c >= 'A' && c <= 'Z'; }
bool isLower( char c ) { return c >= 'a' && c <= 'z'; }

int dr8[8] = { +1, -1, +0, +0, +1, -1, -1, +1};   ///8 direction move
int dc8[8] = { +0, +0, -1, +1, +1, +1, -1, -1};
int dr4[4] = { +0, +0, +1, -1};                   ///4 direction move
int dc4[4] = { -1, +1, +0, +0};                   ///or adjacent dir.
int kn8r[8] = { +1, +2, +2, +1, -1, -2, -2, -1};  ///knight moves
int kn8c[8] = { +2, +1, -1, -2, -2, -1, +1, +2};

const double EPS = 1e-9;                         ///constants
const int INF = ( 1 << 30 ) - 1;
const i64 LINF = ( 1ll << 62 ) - 1;
const int mod = ( int )1e9 + 7;
const int MAX = ( int )1e5;
///____________________________Main Coding Starts From Here________________________///

vector< vector<int> > segments, input;

int main() {
#ifndef ONLINE_JUDGE
//    READ("in.txt");
//    WRITE("out.txt");
    deb_mode = 1;
#endif
    if( deb_mode )
        srand( int( time( NULL ) ) );

    int i, j, k, l, n, m, q, a, b, c;
    CI( n, m );
    i64 ans = 0;
    int frInx;
    vector<int> nowChain;
    rep1( i, m ) {
        CI( q );
        rep1( j, q ) {
            CI( a );
            nowChain.pb( a );
            if(a==1)frInx=i-1;
        }
        input.pb( nowChain );
        nowChain.clear();
    }

    for(i=0;i<m;i++){
        if(i==frInx){
            for(j=0;j<input[i].size();j++){
                int nw=input[i][j];
                if(nowChain.size()==0)nowChain.pb(nw);
                else if(nowChain.back()+1==nw)nowChain.pb(nw);
                else {
                    //debug(nowChain);
                    break;
                }
            }
            if(nowChain.size()!=input[i].size()){
                int t=input[i].size()-nowChain.size();
                ans+=t;
                ans+=t;
            }
        }
        else{
            ans+=input[i].size(); //adding cost
            ans+=input[i].size()-1; //splitting cost
        }
    }
    cout << ans << "\n";

    if( deb_mode )
        cerr << "TIME = " << clock() << " ms" << endl;
    return 0;
}


#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

#define spc        printf(" ")
#define nln        puts("")                         ///printnewline
#define Max(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define Min(a,b,c) min(a,min(b,c))                  ///3 ta theke min
#define sqr(x)     (x)*(x)

#define z(x)       fabs(x)<EPS
#define iqu(x,y)   z(fabs(x-y))

#define rep(i,a,b)  for(i=a;i<=b;i++)
#define rep0(i,n)   for(i=0;i<n;i++)
#define rep1(i,n)   for(i=1;i<=n;i++)               ///looping
#define rev(i,a,b)  for(i=a;i>=b;i--)
#define rev0(i,n)   for(i=n-1;i>=0;i--)
#define rev1(i,n)   for(i=n;i>=1;i--)
#define forstl(i,v) for(i=0;i<v.size();i++)
#define forit(it,v)    for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(p)      p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define vi         vector<int>
#define vll        vector<long long>
#define vs         vector<string>
#define pii        pair<int,int>
#define pll        pair<long long,long long>
#define sz(c)      (int)c.size()
#define pb(x)      push_back(x)                     ///STL defines
#define mp(x,y)    make_pair(x,y)
#define xx         first
#define yy         second
#define _itr(v)    __typeof(v.begin())

#define LLI        long long int
#define i64        long long int
#define i64u       unsigned long long int
#define LLU        unsigned long long int
#define Double     long double
#define PI         acos(-1.0)                        ///PI er value

#define check(n, pos)  (bool)(n & (1LL<<(pos)))      ///CHECK
#define biton(n, pos)  (n | (1LL<<(pos)))            ///ON     }-bit opr.
#define bitoff(n, pos) (n & ~(1LL<<(pos)))           ///OFF

// reading and writing case
#define readcase  int cas,kase=0;CI(cas);while((cas--)&&(++kase))
#define printcase printf("Case %d:",kase)

//debugging infinite variable
bool deb_mode = 0;
#define debug(a...)     if(deb_mode){cout<<"Line= "<<__LINE__<<" -> ";Dbug,a,#a;Dbug.printall();cout<<endl;}
class debugger {
    vector<string> vars;
public:
    template<typename T> debugger& operator , ( const T v ) { stringstream ss; ss << v, vars.push_back( ss.str() ); return *this; }
    void printall() { int j = 0, l = vars.size(); for( int i = 0; i < ( l - 1 ); i++ ) { if( i )cout << ", "; for( j; j < vars[l - 1].size(); j++ ) { if( vars[l - 1][j] == ',' ) {j++; break;} cout << vars[l - 1][j]; } cout << " = " << vars[i]; } vars.clear(); }
} Dbug;

///STL printing output stream overloading
template <typename T1, typename T2> inline ostream& operator << ( ostream& os, const pair<T1, T2>& p ) { return os << "(" << p.first << "," << p.second << ")"; }
template <typename T> inline ostream &operator << ( ostream & os, const vector<T>& v ) { bool first = true; os << "{"; for( unsigned int i = 0; i < v.size(); i++ ) { if( !first ) os << ","; os << v[i]; first = false; } return os << "}"; }
template <typename T> inline ostream &operator << (  ostream & os, const set<T>& v ) { bool first = true; os << "{"; for ( typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii; first = false; } return os << "}"; }
template <typename T1, typename T2> inline ostream &operator << ( ostream & os, const map<T1, T2>& v ) { bool first = true; os << "{"; for ( typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii ; first = false; } return os << "}"; }

template <typename T> void getarray( T a[], int b, int e ) { for( int i = b; i < e + b; i++ ) cin >> a[i]; }
template <typename T> void printarray( T a[], int b, int e ) { for( int i = b; i < e - 1 + b; i++ ) cout << a[i] << " "; if( e - 1 + b >= 0 ) cout << a[e - 1 + b] << endl; }
template <typename T> void printV( vector<T> v ) { int sz = v.size(); if( sz ) cout << v[0]; for( int i = 1; i < sz; i++ ) cout << " " << v[i]; nln; }

template <typename T> T gcd( T a, T b ) { if( b == 0 ) return a; return gcd( b, a % b ); }
template <typename T> T BigMod ( T b, T p, T m ) { if ( p == 0 ) return 1; if ( p % 2 == 0 ) { T s = BigMod( b, p / 2, m ); return ( ( s % m ) * ( s % m ) ) % m; } return ( ( b % m ) * ( BigMod( b, p - 1, m ) % m ) ) % m; }
template <typename T> T ModInv ( T b, T m ) { return BigMod( b, m - 2, m ); }

template<class T> inline void read( T &x ) { bool Minus = 0; char c; for( c = getchar(); c <= 32; c = getchar() ) ; if( c == '-' ) Minus = 1, c = getchar(); for( x = 0; c > 32; c = getchar() ) x = x * 10 + c - '0'; if( Minus ) x = -x; }
char getc() { char c; for( c = getchar(); c <= 32; c = getchar() ); return c; }  ///input char with buffering
int CI( int &_x ) { return scanf( "%d", &_x ); }
int CI( int &_x, int &_y ) { return scanf( "%d %d", &_x, &_y ); }
int CI( int &_x, int &_y, int &_z ) { return scanf( "%d %d %d", &_x, &_y, &_z ); }
int CI( int &_a, int &_b, int &_c, int &_d ) { return scanf( "%d %d %d %d", &_a, &_b, &_c, &_d ); }

template <class T> string toString( T n ) { ostringstream oss; oss << n; return oss.str(); }
int toInt( string s ) { int r = 0; istringstream sin( s ); sin >> r; return r; }
i64 toLong( string s ) { i64 r = 0; istringstream sin( s ); sin >> r; return r; }
bool isVowel( char ch ) { ch = tolower( ch ); if( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )return true; return false; }
bool isUpper( char c ) { return c >= 'A' && c <= 'Z'; }
bool isLower( char c ) { return c >= 'a' && c <= 'z'; }

int dr8[8] = { +1, -1, +0, +0, +1, -1, -1, +1};   ///8 direction move
int dc8[8] = { +0, +0, -1, +1, +1, +1, -1, -1};
int dr4[4] = { +0, +0, +1, -1};                   ///4 direction move
int dc4[4] = { -1, +1, +0, +0};                   ///or adjacent dir.
int kn8r[8] = { +1, +2, +2, +1, -1, -2, -2, -1};  ///knight moves
int kn8c[8] = { +2, +1, -1, -2, -2, -1, +1, +2};

const double EPS = 1e-9;                         ///constants
const int INF = ( 1 << 30 ) - 1;
const i64 LINF = ( 1ll << 62 ) - 1;
const int mod = ( int )1e9 + 7;
const int MAX = ( int )1e5;
///____________________________Main Coding Starts From Here________________________///

vector< vector<int> > segments;

int main() {
#ifndef ONLINE_JUDGE
//    READ("in.txt");
//    WRITE("out.txt");
    deb_mode = 1;
#endif
    if( deb_mode )
        srand( int( time( NULL ) ) );

    int i, j, k, l, n, m, q, a, b, c;
    CI( n, m );
    i64 ans = 0;
    rep1( i, m ) {
        vector<int> nowChain;
        CI( q );
        rep1( j, q ) {
            CI( a );
            if( nowChain.size() == 0 ) {
                nowChain.pb( a );
            }
            else {
                if( nowChain.back() + 1 == a ) {
                    nowChain.pb( a );
                }
                else {
                    ans += nowChain.size();
                    //ans += nowChain.size() - 1;
                    segments.pb( nowChain );
                    nowChain.clear();
                    nowChain.pb( a );
                }
            }
        }
        if( nowChain.size() != 0 ) {
            segments.pb( nowChain );
            nowChain.clear();
        }

    }

debug(segments);
    cout << ans + segments.size() - 1 << "\n";

    if( deb_mode )
        cerr << "TIME = " << clock() << " ms" << endl;
    return 0;
}


#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

#define spc        printf(" ")
#define nln        puts("")                         ///printnewline
#define Max(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define Min(a,b,c) min(a,min(b,c))                  ///3 ta theke min
#define sqr(x)     (x)*(x)

#define z(x)       fabs(x)<EPS
#define iqu(x,y)   z(fabs(x-y))

#define rep(i,a,b)  for(i=a;i<=b;i++)
#define rep0(i,n)   for(i=0;i<n;i++)
#define rep1(i,n)   for(i=1;i<=n;i++)               ///looping
#define rev(i,a,b)  for(i=a;i>=b;i--)
#define rev0(i,n)   for(i=n-1;i>=0;i--)
#define rev1(i,n)   for(i=n;i>=1;i--)
#define forstl(i,v) for(i=0;i<v.size();i++)
#define forit(it,v)    for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(p)      p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define vi         vector<int>
#define vll        vector<long long>
#define vs         vector<string>
#define pii        pair<int,int>
#define pll        pair<long long,long long>
#define sz(c)      (int)c.size()
#define pb(x)      push_back(x)                     ///STL defines
#define mp(x,y)    make_pair(x,y)
#define xx         first
#define yy         second
#define _itr(v)    __typeof(v.begin())

#define LLI        long long int
#define i64        long long int
#define i64u       unsigned long long int
#define LLU        unsigned long long int
#define Double     long double
#define PI         acos(-1.0)                        ///PI er value

#define check(n, pos)  (bool)(n & (1LL<<(pos)))      ///CHECK
#define biton(n, pos)  (n | (1LL<<(pos)))            ///ON     }-bit opr.
#define bitoff(n, pos) (n & ~(1LL<<(pos)))           ///OFF

// reading and writing case
#define readcase  int cas,kase=0;CI(cas);while((cas--)&&(++kase))
#define printcase printf("Case %d:",kase)

//debugging infinite variable
bool deb_mode = 0;
#define debug(a...)     if(deb_mode){cout<<"Line= "<<__LINE__<<" -> ";Dbug,a,#a;Dbug.printall();cout<<endl;}
class debugger {
    vector<string> vars;
public:
    template<typename T> debugger& operator , ( const T v ) { stringstream ss; ss << v, vars.push_back( ss.str() ); return *this; }
    void printall() { int j = 0, l = vars.size(); for( int i = 0; i < ( l - 1 ); i++ ) { if( i )cout << ", "; for( j; j < vars[l - 1].size(); j++ ) { if( vars[l - 1][j] == ',' ) {j++; break;} cout << vars[l - 1][j]; } cout << " = " << vars[i]; } vars.clear(); }
} Dbug;

///STL printing output stream overloading
template <typename T1, typename T2> inline ostream& operator << ( ostream& os, const pair<T1, T2>& p ) { return os << "(" << p.first << "," << p.second << ")"; }
template <typename T> inline ostream &operator << ( ostream & os, const vector<T>& v ) { bool first = true; os << "{"; for( unsigned int i = 0; i < v.size(); i++ ) { if( !first ) os << ","; os << v[i]; first = false; } return os << "}"; }
template <typename T> inline ostream &operator << (  ostream & os, const set<T>& v ) { bool first = true; os << "{"; for ( typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii; first = false; } return os << "}"; }
template <typename T1, typename T2> inline ostream &operator << ( ostream & os, const map<T1, T2>& v ) { bool first = true; os << "{"; for ( typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii ; first = false; } return os << "}"; }

template <typename T> void getarray( T a[], int b, int e ) { for( int i = b; i < e + b; i++ ) cin >> a[i]; }
template <typename T> void printarray( T a[], int b, int e ) { for( int i = b; i < e - 1 + b; i++ ) cout << a[i] << " "; if( e - 1 + b >= 0 ) cout << a[e - 1 + b] << endl; }
template <typename T> void printV( vector<T> v ) { int sz = v.size(); if( sz ) cout << v[0]; for( int i = 1; i < sz; i++ ) cout << " " << v[i]; nln; }

template <typename T> T gcd( T a, T b ) { if( b == 0 ) return a; return gcd( b, a % b ); }
template <typename T> T BigMod ( T b, T p, T m ) { if ( p == 0 ) return 1; if ( p % 2 == 0 ) { T s = BigMod( b, p / 2, m ); return ( ( s % m ) * ( s % m ) ) % m; } return ( ( b % m ) * ( BigMod( b, p - 1, m ) % m ) ) % m; }
template <typename T> T ModInv ( T b, T m ) { return BigMod( b, m - 2, m ); }

template<class T> inline void read( T &x ) { bool Minus = 0; char c; for( c = getchar(); c <= 32; c = getchar() ) ; if( c == '-' ) Minus = 1, c = getchar(); for( x = 0; c > 32; c = getchar() ) x = x * 10 + c - '0'; if( Minus ) x = -x; }
char getc() { char c; for( c = getchar(); c <= 32; c = getchar() ); return c; }  ///input char with buffering
int CI( int &_x ) { return scanf( "%d", &_x ); }
int CI( int &_x, int &_y ) { return scanf( "%d %d", &_x, &_y ); }
int CI( int &_x, int &_y, int &_z ) { return scanf( "%d %d %d", &_x, &_y, &_z ); }
int CI( int &_a, int &_b, int &_c, int &_d ) { return scanf( "%d %d %d %d", &_a, &_b, &_c, &_d ); }

template <class T> string toString( T n ) { ostringstream oss; oss << n; return oss.str(); }
int toInt( string s ) { int r = 0; istringstream sin( s ); sin >> r; return r; }
i64 toLong( string s ) { i64 r = 0; istringstream sin( s ); sin >> r; return r; }
bool isVowel( char ch ) { ch = tolower( ch ); if( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )return true; return false; }
bool isUpper( char c ) { return c >= 'A' && c <= 'Z'; }
bool isLower( char c ) { return c >= 'a' && c <= 'z'; }

int dr8[8] = { +1, -1, +0, +0, +1, -1, -1, +1};   ///8 direction move
int dc8[8] = { +0, +0, -1, +1, +1, +1, -1, -1};
int dr4[4] = { +0, +0, +1, -1};                   ///4 direction move
int dc4[4] = { -1, +1, +0, +0};                   ///or adjacent dir.
int kn8r[8] = { +1, +2, +2, +1, -1, -2, -2, -1};  ///knight moves
int kn8c[8] = { +2, +1, -1, -2, -2, -1, +1, +2};

const double EPS = 1e-9;                         ///constants
const int INF = ( 1 << 30 ) - 1;
const i64 LINF = ( 1ll << 62 ) - 1;
const int mod = ( int )1e9 + 7;
const int MAX = ( int )1e5;
///____________________________Main Coding Starts From Here________________________///

vector< vector<int> > segments,input;

int main() {
#ifndef ONLINE_JUDGE
//    READ("in.txt");
//    WRITE("out.txt");
    deb_mode = 1;
#endif
    if( deb_mode )
        srand( int( time( NULL ) ) );

    int i, j, k, l, n, m, q, a, b, c;
    CI( n, m );
    i64 ans = 0;
    rep1( i, m ) {
        vector<int> nowChain;
        CI( q );
        rep1( j, q ) {
            CI( a );
            nowChain.pb(a);
        }
        if( nowChain.size() != 0 )
            input.pb( nowChain );
        nowChain.clear();
    }

    for(i=0;i<m;i++){
        vector<int> nowChain;
        for(j=input[i].size()-1;j>=0;j--){
            int nw=input[i][j];
            if(nowChain.size()==0){
                nowChain.pb(input[i][j]);
            }
            else{
                if(nw+1==nowChain.back())
                    nowChain.pb(nw);
                else{
                    segments.pb(nowChain);
                    ans+=nowChain.size();
                    ans+=nowChain.size()-1;
                    nowChain.clear();
                    nowChain.pb(nw);
                }
            }
        }
        if(nowChain.size()!=0){
            segments.pb(nowChain);
            nowChain.clear();
        }
    }

    //debug(input);
    //debug(segments);
    cout << ans + segments.size() - 1 << "\n";

    if( deb_mode )
        cerr << "TIME = " << clock() << " ms" << endl;
    return 0;
}


#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

#define spc        printf(" ")
#define nln        puts("")                         ///printnewline
#define Max(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define Min(a,b,c) min(a,min(b,c))                  ///3 ta theke min
#define sqr(x)     (x)*(x)

#define z(x)       fabs(x)<EPS
#define iqu(x,y)   z(fabs(x-y))

#define rep(i,a,b)  for(i=a;i<=b;i++)
#define rep0(i,n)   for(i=0;i<n;i++)
#define rep1(i,n)   for(i=1;i<=n;i++)               ///looping
#define rev(i,a,b)  for(i=a;i>=b;i--)
#define rev0(i,n)   for(i=n-1;i>=0;i--)
#define rev1(i,n)   for(i=n;i>=1;i--)
#define forstl(i,v) for(i=0;i<v.size();i++)
#define forit(it,v)    for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(p)      p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define vi         vector<int>
#define vll        vector<long long>
#define vs         vector<string>
#define pii        pair<int,int>
#define pll        pair<long long,long long>
#define sz(c)      (int)c.size()
#define pb(x)      push_back(x)                     ///STL defines
#define mp(x,y)    make_pair(x,y)
#define xx         first
#define yy         second
#define _itr(v)    __typeof(v.begin())

#define LLI        long long int
#define i64        long long int
#define i64u       unsigned long long int
#define LLU        unsigned long long int
#define Double     long double
#define PI         acos(-1.0)                        ///PI er value

#define check(n, pos)  (bool)(n & (1LL<<(pos)))      ///CHECK
#define biton(n, pos)  (n | (1LL<<(pos)))            ///ON     }-bit opr.
#define bitoff(n, pos) (n & ~(1LL<<(pos)))           ///OFF

// reading and writing case
#define readcase  int cas,kase=0;CI(cas);while((cas--)&&(++kase))
#define printcase printf("Case %d:",kase)

//debugging infinite variable
bool deb_mode = 0;
#define debug(a...)     if(deb_mode){cout<<"Line= "<<__LINE__<<" -> ";Dbug,a,#a;Dbug.printall();cout<<endl;}
class debugger {
    vector<string> vars;
public:
    template<typename T> debugger& operator , ( const T v ) { stringstream ss; ss << v, vars.push_back( ss.str() ); return *this; }
    void printall() { int j = 0, l = vars.size(); for( int i = 0; i < ( l - 1 ); i++ ) { if( i )cout << ", "; for( j; j < vars[l - 1].size(); j++ ) { if( vars[l - 1][j] == ',' ) {j++; break;} cout << vars[l - 1][j]; } cout << " = " << vars[i]; } vars.clear(); }
} Dbug;

///STL printing output stream overloading
template <typename T1, typename T2> inline ostream& operator << ( ostream& os, const pair<T1, T2>& p ) { return os << "(" << p.first << "," << p.second << ")"; }
template <typename T> inline ostream &operator << ( ostream & os, const vector<T>& v ) { bool first = true; os << "{"; for( unsigned int i = 0; i < v.size(); i++ ) { if( !first ) os << ","; os << v[i]; first = false; } return os << "}"; }
template <typename T> inline ostream &operator << (  ostream & os, const set<T>& v ) { bool first = true; os << "{"; for ( typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii; first = false; } return os << "}"; }
template <typename T1, typename T2> inline ostream &operator << ( ostream & os, const map<T1, T2>& v ) { bool first = true; os << "{"; for ( typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii ; first = false; } return os << "}"; }

template <typename T> void getarray( T a[], int b, int e ) { for( int i = b; i < e + b; i++ ) cin >> a[i]; }
template <typename T> void printarray( T a[], int b, int e ) { for( int i = b; i < e - 1 + b; i++ ) cout << a[i] << " "; if( e - 1 + b >= 0 ) cout << a[e - 1 + b] << endl; }
template <typename T> void printV( vector<T> v ) { int sz = v.size(); if( sz ) cout << v[0]; for( int i = 1; i < sz; i++ ) cout << " " << v[i]; nln; }

template <typename T> T gcd( T a, T b ) { if( b == 0 ) return a; return gcd( b, a % b ); }
template <typename T> T BigMod ( T b, T p, T m ) { if ( p == 0 ) return 1; if ( p % 2 == 0 ) { T s = BigMod( b, p / 2, m ); return ( ( s % m ) * ( s % m ) ) % m; } return ( ( b % m ) * ( BigMod( b, p - 1, m ) % m ) ) % m; }
template <typename T> T ModInv ( T b, T m ) { return BigMod( b, m - 2, m ); }

template<class T> inline void read( T &x ) { bool Minus = 0; char c; for( c = getchar(); c <= 32; c = getchar() ) ; if( c == '-' ) Minus = 1, c = getchar(); for( x = 0; c > 32; c = getchar() ) x = x * 10 + c - '0'; if( Minus ) x = -x; }
char getc() { char c; for( c = getchar(); c <= 32; c = getchar() ); return c; }  ///input char with buffering
int CI( int &_x ) { return scanf( "%d", &_x ); }
int CI( int &_x, int &_y ) { return scanf( "%d %d", &_x, &_y ); }
int CI( int &_x, int &_y, int &_z ) { return scanf( "%d %d %d", &_x, &_y, &_z ); }
int CI( int &_a, int &_b, int &_c, int &_d ) { return scanf( "%d %d %d %d", &_a, &_b, &_c, &_d ); }

template <class T> string toString( T n ) { ostringstream oss; oss << n; return oss.str(); }
int toInt( string s ) { int r = 0; istringstream sin( s ); sin >> r; return r; }
i64 toLong( string s ) { i64 r = 0; istringstream sin( s ); sin >> r; return r; }
bool isVowel( char ch ) { ch = tolower( ch ); if( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )return true; return false; }
bool isUpper( char c ) { return c >= 'A' && c <= 'Z'; }
bool isLower( char c ) { return c >= 'a' && c <= 'z'; }

int dr8[8] = { +1, -1, +0, +0, +1, -1, -1, +1};   ///8 direction move
int dc8[8] = { +0, +0, -1, +1, +1, +1, -1, -1};
int dr4[4] = { +0, +0, +1, -1};                   ///4 direction move
int dc4[4] = { -1, +1, +0, +0};                   ///or adjacent dir.
int kn8r[8] = { +1, +2, +2, +1, -1, -2, -2, -1};  ///knight moves
int kn8c[8] = { +2, +1, -1, -2, -2, -1, +1, +2};

const double EPS = 1e-9;                         ///constants
const int INF = ( 1 << 30 ) - 1;
const i64 LINF = ( 1ll << 62 ) - 1;
const int mod = ( int )1e9 + 7;
const int MAX = ( int )1e5;
///____________________________Main Coding Starts From Here________________________///

vector< vector<int> > segments;

int main() {
#ifndef ONLINE_JUDGE
//    READ("in.txt");
//    WRITE("out.txt");
    deb_mode = 1;
#endif
    if( deb_mode )
        srand( int( time( NULL ) ) );

    int i, j, k, l, n, m, q, a, b, c;
    CI( n, m );
    i64 ans = 0;
    int firstSegmentIndex = -1;
    rep1( i, m ) {
        vector<int> nowChain;
        CI( q );
        rep1( j, q ) {
            CI( a );
            if( a == 1 ) {
                firstSegmentIndex = segments.size();
            }
            if( nowChain.size() == 0 ) {
                nowChain.pb( a );
            }
            else {
                if( nowChain.back() + 1 == a ) {
                    nowChain.pb( a );
                }
                else {
                    ans++;
                    segments.pb( nowChain );
                    nowChain.clear();
                    nowChain.pb( a );
                }
            }
        }
        if( nowChain.size() != 0 )
            segments.pb( nowChain );
        nowChain.clear();
    }

    debug( ans );
    debug( segments );
    debug(firstSegmentIndex);
    for( i = 0; i < segments.size(); i++ ) {
        if( i == firstSegmentIndex )continue;
        debug(segments[i]);
        ans += segments[i].size();
        ans += segments[i].size() - 1;
    }

    cout << ans << "\n";

    if( deb_mode )
        cerr << "TIME = " << clock() << " ms" << endl;
    return 0;
}


#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

#define spc        printf(" ")
#define nln        puts("")                         ///printnewline
#define Max(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define Min(a,b,c) min(a,min(b,c))                  ///3 ta theke min
#define sqr(x)     (x)*(x)

#define z(x)       fabs(x)<EPS
#define iqu(x,y)   z(fabs(x-y))

#define rep(i,a,b)  for(i=a;i<=b;i++)
#define rep0(i,n)   for(i=0;i<n;i++)
#define rep1(i,n)   for(i=1;i<=n;i++)               ///looping
#define rev(i,a,b)  for(i=a;i>=b;i--)
#define rev0(i,n)   for(i=n-1;i>=0;i--)
#define rev1(i,n)   for(i=n;i>=1;i--)
#define forstl(i,v) for(i=0;i<v.size();i++)
#define forit(it,v)    for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(p)      p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define vi         vector<int>
#define vll        vector<long long>
#define vs         vector<string>
#define pii        pair<int,int>
#define pll        pair<long long,long long>
#define sz(c)      (int)c.size()
#define pb(x)      push_back(x)                     ///STL defines
#define mp(x,y)    make_pair(x,y)
#define xx         first
#define yy         second
#define _itr(v)    __typeof(v.begin())

#define LLI        long long int
#define i64        long long int
#define i64u       unsigned long long int
#define LLU        unsigned long long int
#define Double     long double
#define PI         acos(-1.0)                        ///PI er value

#define check(n, pos)  (bool)(n & (1LL<<(pos)))      ///CHECK
#define biton(n, pos)  (n | (1LL<<(pos)))            ///ON     }-bit opr.
#define bitoff(n, pos) (n & ~(1LL<<(pos)))           ///OFF

// reading and writing case
#define readcase  int cas,kase=0;CI(cas);while((cas--)&&(++kase))
#define printcase printf("Case %d:",kase)

//debugging infinite variable
bool deb_mode = 0;
#define debug(a...)     if(deb_mode){cout<<"Line= "<<__LINE__<<" -> ";Dbug,a,#a;Dbug.printall();cout<<endl;}
class debugger {
    vector<string> vars;
public:
    template<typename T> debugger& operator , ( const T v ) { stringstream ss; ss << v, vars.push_back( ss.str() ); return *this; }
    void printall() { int j = 0, l = vars.size(); for( int i = 0; i < ( l - 1 ); i++ ) { if( i )cout << ", "; for( j; j < vars[l - 1].size(); j++ ) { if( vars[l - 1][j] == ',' ) {j++; break;} cout << vars[l - 1][j]; } cout << " = " << vars[i]; } vars.clear(); }
} Dbug;

///STL printing output stream overloading
template <typename T1, typename T2> inline ostream& operator << ( ostream& os, const pair<T1, T2>& p ) { return os << "(" << p.first << "," << p.second << ")"; }
template <typename T> inline ostream &operator << ( ostream & os, const vector<T>& v ) { bool first = true; os << "{"; for( unsigned int i = 0; i < v.size(); i++ ) { if( !first ) os << ","; os << v[i]; first = false; } return os << "}"; }
template <typename T> inline ostream &operator << (  ostream & os, const set<T>& v ) { bool first = true; os << "{"; for ( typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii; first = false; } return os << "}"; }
template <typename T1, typename T2> inline ostream &operator << ( ostream & os, const map<T1, T2>& v ) { bool first = true; os << "{"; for ( typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii ; first = false; } return os << "}"; }

template <typename T> void getarray( T a[], int b, int e ) { for( int i = b; i < e + b; i++ ) cin >> a[i]; }
template <typename T> void printarray( T a[], int b, int e ) { for( int i = b; i < e - 1 + b; i++ ) cout << a[i] << " "; if( e - 1 + b >= 0 ) cout << a[e - 1 + b] << endl; }
template <typename T> void printV( vector<T> v ) { int sz = v.size(); if( sz ) cout << v[0]; for( int i = 1; i < sz; i++ ) cout << " " << v[i]; nln; }

template <typename T> T gcd( T a, T b ) { if( b == 0 ) return a; return gcd( b, a % b ); }
template <typename T> T BigMod ( T b, T p, T m ) { if ( p == 0 ) return 1; if ( p % 2 == 0 ) { T s = BigMod( b, p / 2, m ); return ( ( s % m ) * ( s % m ) ) % m; } return ( ( b % m ) * ( BigMod( b, p - 1, m ) % m ) ) % m; }
template <typename T> T ModInv ( T b, T m ) { return BigMod( b, m - 2, m ); }

template<class T> inline void read( T &x ) { bool Minus = 0; char c; for( c = getchar(); c <= 32; c = getchar() ) ; if( c == '-' ) Minus = 1, c = getchar(); for( x = 0; c > 32; c = getchar() ) x = x * 10 + c - '0'; if( Minus ) x = -x; }
char getc() { char c; for( c = getchar(); c <= 32; c = getchar() ); return c; }  ///input char with buffering
int CI( int &_x ) { return scanf( "%d", &_x ); }
int CI( int &_x, int &_y ) { return scanf( "%d %d", &_x, &_y ); }
int CI( int &_x, int &_y, int &_z ) { return scanf( "%d %d %d", &_x, &_y, &_z ); }
int CI( int &_a, int &_b, int &_c, int &_d ) { return scanf( "%d %d %d %d", &_a, &_b, &_c, &_d ); }

template <class T> string toString( T n ) { ostringstream oss; oss << n; return oss.str(); }
int toInt( string s ) { int r = 0; istringstream sin( s ); sin >> r; return r; }
i64 toLong( string s ) { i64 r = 0; istringstream sin( s ); sin >> r; return r; }
bool isVowel( char ch ) { ch = tolower( ch ); if( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )return true; return false; }
bool isUpper( char c ) { return c >= 'A' && c <= 'Z'; }
bool isLower( char c ) { return c >= 'a' && c <= 'z'; }

int dr8[8] = { +1, -1, +0, +0, +1, -1, -1, +1};   ///8 direction move
int dc8[8] = { +0, +0, -1, +1, +1, +1, -1, -1};
int dr4[4] = { +0, +0, +1, -1};                   ///4 direction move
int dc4[4] = { -1, +1, +0, +0};                   ///or adjacent dir.
int kn8r[8] = { +1, +2, +2, +1, -1, -2, -2, -1};  ///knight moves
int kn8c[8] = { +2, +1, -1, -2, -2, -1, +1, +2};

const double EPS = 1e-9;                         ///constants
const int INF = ( 1 << 30 ) - 1;
const i64 LINF = ( 1ll << 62 ) - 1;
const int mod = ( int )1e9 + 7;
const int MAX = ( int )1e5;
///____________________________Main Coding Starts From Here________________________///

vector< vector<int> > segments;

int main() {
#ifndef ONLINE_JUDGE
//    READ("in.txt");
//    WRITE("out.txt");
    deb_mode = 1;
#endif
    if( deb_mode )
        srand( int( time( NULL ) ) );

    int i, j, k, l, n, m, q, a, b, c;
    CI( n, m );
    i64 ans = 0;
    rep1( i, m ) {
        vector<int> nowChain;
        CI( q );
        rep1( j, q ) {
            CI( a );
            if( nowChain.size() == 0 ) {
                nowChain.pb( a );
            }
            else {
                if( nowChain.back() + 1 == a ) {
                    nowChain.pb( a );
                }
                else {
                    ans += nowChain.size();
                    ans += nowChain.size() - 1;
                    segments.pb( nowChain );
                    nowChain.clear();
                    nowChain.pb( a );
                }
            }
        }
        if( nowChain.size() != 0 ) {
            segments.pb( nowChain );
            nowChain.clear();
        }

    }

//debug(segments);
    cout << ans + segments.size() - 1 << "\n";

    if( deb_mode )
        cerr << "TIME = " << clock() << " ms" << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<stack>

using namespace std;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int *m=new int[k];
    stack<int> s[k];
    int x;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&m[i]);
        for(int j=0;j<m[i];j++)
        {
            scanf("%d",&x);
            s[i].push(x);
        }
    }
    stack<int> final;
    int time=0;
    while(final.size()!=n)
    {
        int max=0,index=0;
        for(int i=0;i<k;i++)
        {
            if(!s[i].empty() && s[i].top()>max)
            {
                max=s[i].top();
                index=i;
            }
        }
        int prev=max;
        int temp=time;
        s[index].pop();
        time++;
        int top=max;
        if(final.size()!=0)
        {
            top=final.top();
            time++;
        }
        final.push(max);
        int count=0;
        while(!s[index].empty() && s[index].top()==prev-1)
        {
            final.push(s[index].top());
            s[index].pop();
            count++;
        }
        if(!s[index].empty())
        {
            time+=2*count;
        }
        else
        {
            time=temp;
            if(final.size()!=0 && top!=max)
            {
                time++;
            }
        }
        //cout<<time<<endl;
    }
    cout<<time<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<stack>

using namespace std;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int *m=new int[k];
    stack<int> s[k];
    int x;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&m[i]);
        for(int j=0;j<m[i];j++)
        {
            scanf("%d",&x);
            s[i].push(x);
        }
    }
    stack<int> final;
    int time=0;
    while(final.size()!=n)
    {
        int max=0,index=0;
        for(int i=0;i<k;i++)
        {
            if(!s[i].empty() && s[i].top()>max)
            {
                max=s[i].top();
                index=i;
            }
        }
        int prev=max;
        int temp=time;
        s[index].pop();
        time++;
        int top=max;
        if(final.size()!=0)
        {
            top=final.top();
            time++;
        }
        final.push(max);
        int count=0;
        while(!s[index].empty() && s[index].top()==prev-1)
        {
            final.push(s[index].top());
            prev=s[index].top();
            s[index].pop();
            count++;
        }
        //cout<<count<<endl;
        if(!s[index].empty())
        {
            time+=2*count;
        }
        else
        {
            time=temp;
            //cout<<"a1"<<endl;
            if(final.size()!=0 && top!=max)
            {
                time++;
            }
        }
        //acout<<time<<endl;
    }
    cout<<time<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>

using namespace std;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int *m=new int[k];
    queue<int> s[k];
    int x;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&m[i]);
        for(int j=0;j<m[i];j++)
        {
            scanf("%d",&x);
            s[i].push(x);
        }
    }
    stack<int> final;
    long long time=0;
    int min=100001,index=0;
    for(int i=0;i<k;i++)
    {
        if(!s[i].empty() && s[i].front()<min)
        {
            min=s[i].front();
            index=i;
        }
    }
    int prev=min-1;
    while(!s[index].empty() && s[index].front()==prev+1)
    {
        final.push(s[index].front());
        prev=final.top();
        s[index].pop();
    }
    if(s[index].empty())
    {
        time=0;
    }
    else
    {
        time++;
    }
    //cout<<time<<endl;
    while(final.size()!=n)
    {
        min=100001;
        index=0;
        for(int i=0;i<k;i++)
        {
            if(!s[i].empty() && s[i].front()<min)
            {
                min=s[i].front();
                index=i;
            }
        }
        prev=min-1;
        while(!s[index].empty() && s[index].front()==prev+1)
        {
            final.push(s[index].front());
            if(s[index].size()>1)
                time+=2;
            else
                time++;
            prev=final.top();
            s[index].pop();
        }
        //cout<<time<<endl;
    }
    cout<<time<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<set>

using namespace std;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int *m=new int[k];
    queue<int> s[k];
    int x;
    map<int,int> mymap;
    set<int> myset;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&m[i]);
        scanf("%d",&x);
        myset.insert(x);
        s[i].push(x);
        mymap[x]=i;
        for(int j=1;j<m[i];j++)
        {
            scanf("%d",&x);
            s[i].push(x);
        }
    }
    stack<int> final;
    long long time=0;
    set<int>::iterator it=myset.begin();
    int index=mymap[*it];
    int prev=*it-1;
    while(!s[index].empty() && s[index].front()==prev+1)
    {
        final.push(s[index].front());
        prev=final.top();
        s[index].pop();

    }
    if(s[index].empty())
    {
        time=0;
    }
    else
    {
        mymap[s[index].front()]=index;
        myset.insert(s[index].front());
        time++;
    }
    it++;
    //cout<<time<<endl;
    while(final.size()!=n)
    {
        /*min=100001;
        index=0;
        for(int i=0;i<k;i++)
        {
            if(!s[i].empty() && s[i].front()<min)
            {
                min=s[i].front();
                index=i;
            }
        }*/
        index=mymap[*it];
        prev=*it-1;
        while(!s[index].empty() && s[index].front()==prev+1)
        {
            final.push(s[index].front());
            if(s[index].size()>1)
                time+=2;
            else
                time++;
            prev=final.top();
            s[index].pop();
        }
        if(!s[index].empty())
        {
            mymap[s[index].front()]=index;
            myset.insert(s[index].front());
        }
        it++;
        //cout<<time<<endl;
    }
    cout<<time<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<stack>

using namespace std;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int *m=new int[k];
    stack<int> s[k];
    int x;
    for(int i=0;i<k;i++)
    {
        scanf("%d",&m[i]);
        for(int j=0;j<m[i];j++)
        {
            scanf("%d",&x);
            s[i].push(x);
        }
    }
    stack<int> final;
    long long time=0;
    while(final.size()!=n)
    {
        int max=0,index=0;
        for(int i=0;i<k;i++)
        {
            if(!s[i].empty() && s[i].top()>max)
            {
                max=s[i].top();
                index=i;
            }
        }
        int prev=max;
        long long temp=time;
        s[index].pop();
        time++;
        int top=max;
        if(final.size()!=0)
        {
            top=final.top();
            time++;
        }
        final.push(max);
        int count=0;
        while(!s[index].empty() && s[index].top()==prev-1)
        {
            final.push(s[index].top());
            prev=s[index].top();
            s[index].pop();
            count++;
        }
        //cout<<count<<endl;
        if(!s[index].empty())
        {
            time+=2*count;
        }
        else
        {
            time=temp;
            //cout<<"a1"<<endl;
            if(final.size()!=0 && top!=max)
            {
                time++;
            }
        }
        //acout<<time<<endl;
    }
    cout<<time<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000005
#define INF 1000000001
#define MOD 1000000007

#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define mset(a,b) memset(a,b,sizeof(a))
#define m2set(a,m,n,b) memset(a,b,sizeof(a[0][0])*m*n)
#define graphclear(g) for(int i=1;i<=n;i++)g[i].clear()

#define inp_s     ios_base::sync_with_stdio(false);cin.tie(0)
#define test()     int test;cin>>test;while(test--)

struct sort_pred {
	bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
		return left.second < right.second;
	}
};
//sort(v,v+n,sort_pred())

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef vector < ll > vll;
typedef vector < vll > vvll;
typedef pair < ll,ll > ll2;
typedef vector < ll2 > vll2;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int,int > ii;
typedef vector < ii > vii;
typedef vector < vii > vvii;

#define tr(c,it) for(typeof(c.begin()) it = c.begin(); it != c.end(); it++)

#define gc getchar
#define pc putchar
#define endl "\n"
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define pin(n) printf("%d\n",n)
#define plln(n) printf("%lld\n",n)
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)

int gcd(int a, int b)	{return (a == 0) ? b : gcd(b%a, a);}
ll powmod(ll a,ll b){if(b==0)return 1;ll x=powmod(a,b/2);ll y=(x*x)%MOD;if(b%2)return (a*y)%MOD;return y%MOD;}
int main()
{
	inp_s;
	//test();
	int n,k;
	cin >> n >> k;
	int m[100005];
	int cnt=0;
	int mk=INF;
	vvi a(100005);
	rep(i,k)
	{
		cin >> m[i];
		int pr;
		cin >> pr;
		a[i].pb(pr);
		int x;
		rep(j,m[i]-1)
		{
			cin >> x;
			a[i].pb(x);
			if(x!=pr+1)mk=MIN(pr,mk);
			pr=x;
		}
		mk=MIN(mk,pr);
	}
	rep(i,k)
		rep(j,m[i]-1)
			if(a[i][j]!=a[i][j+1]-1 || a[i][j]>mk)cnt++;
	cout << k+2*cnt-1 << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000005
#define INF 1000000001
#define MOD 1000000007

#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define mset(a,b) memset(a,b,sizeof(a))
#define m2set(a,m,n,b) memset(a,b,sizeof(a[0][0])*m*n)
#define graphclear(g) for(int i=1;i<=n;i++)g[i].clear()

#define inp_s     ios_base::sync_with_stdio(false);cin.tie(0)
#define test()     int test;cin>>test;while(test--)

struct sort_pred {
	bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
		return left.second < right.second;
	}
};
//sort(v,v+n,sort_pred())

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef vector < ll > vll;
typedef vector < vll > vvll;
typedef pair < ll,ll > ll2;
typedef vector < ll2 > vll2;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int,int > ii;
typedef vector < ii > vii;
typedef vector < vii > vvii;

#define tr(c,it) for(typeof(c.begin()) it = c.begin(); it != c.end(); it++)

#define gc getchar
#define pc putchar
#define endl "\n"
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define pin(n) printf("%d\n",n)
#define plln(n) printf("%lld\n",n)
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)

int gcd(int a, int b)	{return (a == 0) ? b : gcd(b%a, a);}
ll powmod(ll a,ll b){if(b==0)return 1;ll x=powmod(a,b/2);ll y=(x*x)%MOD;if(b%2)return (a*y)%MOD;return y%MOD;}
int main()
{
	inp_s;
	//test();
	int n,k;
	cin >> n >> k;
	int m;
	int cnt=0;
	rep(i,k)
	{
		cin >> m;
		int pr;
		cin >> pr;
		rep(j,m-1)
		{
			int x;
			cin >> x;
			if(x!=pr+1)cnt++;
			pr=x;
		}
	}
	cout << k+2*cnt-1 << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000005
#define INF 1000000001
#define MOD 1000000007

#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define mset(a,b) memset(a,b,sizeof(a))
#define m2set(a,m,n,b) memset(a,b,sizeof(a[0][0])*m*n)
#define graphclear(g) for(int i=1;i<=n;i++)g[i].clear()

#define inp_s     ios_base::sync_with_stdio(false);cin.tie(0)
#define test()     int test;cin>>test;while(test--)

struct sort_pred {
	bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
		return left.second < right.second;
	}
};
//sort(v,v+n,sort_pred())

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef vector < ll > vll;
typedef vector < vll > vvll;
typedef pair < ll,ll > ll2;
typedef vector < ll2 > vll2;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int,int > ii;
typedef vector < ii > vii;
typedef vector < vii > vvii;

#define tr(c,it) for(typeof(c.begin()) it = c.begin(); it != c.end(); it++)

#define gc getchar
#define pc putchar
#define endl "\n"
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define pin(n) printf("%d\n",n)
#define plln(n) printf("%lld\n",n)
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)

int gcd(int a, int b)	{return (a == 0) ? b : gcd(b%a, a);}
ll powmod(ll a,ll b){if(b==0)return 1;ll x=powmod(a,b/2);ll y=(x*x)%MOD;if(b%2)return (a*y)%MOD;return y%MOD;}
int main()
{
	inp_s;
	//test();
	int n,k;
	cin >> n >> k;
	int m[100005];
	int cnt=0;
	int mk=INF;
	vvi a(100005);
	rep(i,k)
	{
		cin >> m[i];
		int pr;
		cin >> pr;
		a[i].pb(pr);
		rep(j,m[i]-1)
		{
			int x;
			cin >> x;
			a[i].pb(x);
			if(x!=pr+1 && pr<mk)mk=pr;
			pr=x;
		}
	}
	rep(i,k)
		rep(j,m[i]-1)
			if(a[i][j]!=a[i][j+1]-1 || a[i][j]>mk)cnt++;
	cout << k+2*cnt-1 << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000005
#define INF 1000000001
#define MOD 1000000007

#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define mset(a,b) memset(a,b,sizeof(a))
#define m2set(a,m,n,b) memset(a,b,sizeof(a[0][0])*m*n)
#define graphclear(g) for(int i=1;i<=n;i++)g[i].clear()

#define inp_s     ios_base::sync_with_stdio(false);cin.tie(0)
#define test()     int test;cin>>test;while(test--)

struct sort_pred {
	bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
		return left.second < right.second;
	}
};
//sort(v,v+n,sort_pred())

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef vector < ll > vll;
typedef vector < vll > vvll;
typedef pair < ll,ll > ll2;
typedef vector < ll2 > vll2;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int,int > ii;
typedef vector < ii > vii;
typedef vector < vii > vvii;

#define tr(c,it) for(typeof(c.begin()) it = c.begin(); it != c.end(); it++)

#define gc getchar
#define pc putchar
#define endl "\n"
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define pin(n) printf("%d\n",n)
#define plln(n) printf("%lld\n",n)
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)

int gcd(int a, int b)	{return (a == 0) ? b : gcd(b%a, a);}
ll powmod(ll a,ll b){if(b==0)return 1;ll x=powmod(a,b/2);ll y=(x*x)%MOD;if(b%2)return (a*y)%MOD;return y%MOD;}
int main()
{
	inp_s;
	//test();
	int n,k;
	cin >> n >> k;
	int m[100005];
	int cnt=0;
	int mk=INF;
	vvi a(100005);
	rep(i,k)
	{
		cin >> m[i];
		int pr;
		cin >> pr;
		a[i].pb(pr);
		rep(j,m[i]-1)
		{
			int x;
			cin >> x;
			a[i].pb(x);
			if(x!=pr+1 && pr<mk)mk=pr;
		}
	}
	rep(i,k)
		rep(j,m[i]-1)
			if(a[i][j]!=a[i][j+1]-1 || a[i][j]>mk)cnt++;
	cout << k+2*cnt-1 << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000005
#define INF 1000000001
#define MOD 1000000007

#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define mset(a,b) memset(a,b,sizeof(a))
#define m2set(a,m,n,b) memset(a,b,sizeof(a[0][0])*m*n)
#define graphclear(g) for(int i=1;i<=n;i++)g[i].clear()

#define inp_s     ios_base::sync_with_stdio(false);cin.tie(0)
#define test()     int test;cin>>test;while(test--)

struct sort_pred {
	bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
		return left.second < right.second;
	}
};
//sort(v,v+n,sort_pred())

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef vector < ll > vll;
typedef vector < vll > vvll;
typedef pair < ll,ll > ll2;
typedef vector < ll2 > vll2;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int,int > ii;
typedef vector < ii > vii;
typedef vector < vii > vvii;

#define tr(c,it) for(typeof(c.begin()) it = c.begin(); it != c.end(); it++)

#define gc getchar
#define pc putchar
#define endl "\n"
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define pin(n) printf("%d\n",n)
#define plln(n) printf("%lld\n",n)
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)

int gcd(int a, int b)	{return (a == 0) ? b : gcd(b%a, a);}
ll powmod(ll a,ll b){if(b==0)return 1;ll x=powmod(a,b/2);ll y=(x*x)%MOD;if(b%2)return (a*y)%MOD;return y%MOD;}
int main()
{
	inp_s;
	//test();
	int n,k;
	cin >> n >> k;
	int m[100005];
	int cnt=0;
	int mk=INF;
	vvi a(100005);
	rep(i,k)
	{
		cin >> m[i];
		int pr;
		cin >> pr;
		a[i].pb(pr);
		rep(j,m[i]-1)
		{
			int x;
			cin >> x;
			a[i].pb(x);
			if(x!=pr+1 && x<mk)mk=x;
		}
	}
	rep(i,k)
		rep(j,m[i]-1)
			if(a[i][j]!=a[i][j+1]-1 || a[i][j]>mk)cnt++;
	cout << k+2*cnt-1 << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000005
#define INF 1000000001
#define MOD 1000000007

#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define mset(a,b) memset(a,b,sizeof(a))
#define m2set(a,m,n,b) memset(a,b,sizeof(a[0][0])*m*n)
#define graphclear(g) for(int i=1;i<=n;i++)g[i].clear()

#define inp_s     ios_base::sync_with_stdio(false);cin.tie(0)
#define test()     int test;cin>>test;while(test--)

struct sort_pred {
	bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
		return left.second < right.second;
	}
};
//sort(v,v+n,sort_pred())

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef vector < ll > vll;
typedef vector < vll > vvll;
typedef pair < ll,ll > ll2;
typedef vector < ll2 > vll2;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int,int > ii;
typedef vector < ii > vii;
typedef vector < vii > vvii;

#define tr(c,it) for(typeof(c.begin()) it = c.begin(); it != c.end(); it++)

#define gc getchar
#define pc putchar
#define endl "\n"
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define pin(n) printf("%d\n",n)
#define plln(n) printf("%lld\n",n)
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)

int gcd(int a, int b)	{return (a == 0) ? b : gcd(b%a, a);}
ll powmod(ll a,ll b){if(b==0)return 1;ll x=powmod(a,b/2);ll y=(x*x)%MOD;if(b%2)return (a*y)%MOD;return y%MOD;}
int main()
{
	inp_s;
	//test();
	int n,k;
	cin >> n >> k;
	int m[100005];
	int cnt=0;
	int mk=INF;
	vvi a(100005);
	rep(i,k)
	{
		cin >> m[i];
		int pr;
		cin >> pr;
		a[i].pb(pr);
		int x;
		rep(j,m[i]-1)
		{
			cin >> x;
			a[i].pb(x);
			if(x!=pr+1)mk=MIN(pr,mk);
			pr=x;
		}
		mk=MIN(mk,x);
	}
	rep(i,k)
		rep(j,m[i]-1)
			if(a[i][j]!=a[i][j+1]-1 || a[i][j]>mk)cnt++;
	cout << k+2*cnt-1 << endl;
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

long long n, k;
long long ans, sub;
long long tmp[100005];

int main()
{
    freopen("text.inp", "rt", stdin);
    scanf("%I64d %I64d", &n, &k);
    ans = n-1;
    sub = 0;
    for(int i = 0; i < k; i++)
    {
        memset(tmp, 0, sizeof(tmp));
        long long cnt;
        scanf("%I64d", &cnt);
        ans += cnt-1;
        for(int j = 0; j < cnt; j++)
            scanf("%I64d", &tmp[j]);
        if(tmp[0] == 1)
        {
            for(int j = 0; j < cnt; j++)
            {
                if(tmp[j] == tmp[j+1]-1)
                    sub++;
            }
        }
    }
    sub = 2*sub;
    ans -= sub;
    printf("%I64d", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

long long n, k;
long long ans, sub;
long long tmp[100005];

int main()
{
    scanf("%I64d %I64d", &n, &k);
    ans = n-1;
    sub = 0;
    for(int i = 0; i < k; i++)
    {
        memset(tmp, 0, sizeof(tmp));
        long long cnt;
        scanf("%I64d", &cnt);
        ans += cnt-1;
        for(int j = 0; j < cnt; j++)
            scanf("%I64d", &tmp[j]);
        if(tmp[0] == 1)
        {
            for(int j = 0; j < cnt; j++)
            {
                if(tmp[j] == tmp[j+1]-1)
                    sub++;
            }
        }
    }
    printf("%I64d", ans-2*sub);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

long long n, k;
long long ans, sub;
long long tmp[100005];

int main()
{
   // freopen("text.inp", "rt", stdin);
    scanf("%I64d %I64d", &n, &k);
    ans = n-1;
    sub = 0;
    for(int i = 0; i < k; i++)
    {
       // memset(tmp, 0, sizeof(tmp));
        long long cnt;
        scanf("%I64d", &cnt);
        ans += cnt-1;
        for(int j = 0; j < cnt; j++)
            scanf("%I64d", &tmp[j]);
        if(tmp[0] == 1)
        {
            for(int j = 0; j < cnt-1; j++)
            {
                if(tmp[j] == tmp[j+1]-1)
                    sub++;
            }
        }
    }
    sub = 2*(sub-1);
    ans -= sub;
    printf("%I64d", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

long long n, k;
long long ans, sub;
long long tmp[100005];

int main()
{
   // freopen("text.inp", "rt", stdin);
    scanf("%I64d %I64d", &n, &k);
    ans = n-1;
    sub = 0;
    for(int i = 0; i < k; i++)
    {
       // memset(tmp, 0, sizeof(tmp));
        long long cnt;
        scanf("%I64d", &cnt);
        ans += cnt-1;
        for(int j = 0; j < cnt; j++)
            scanf("%I64d", &tmp[j]);
        if(tmp[0] == 1)
        {
            for(int j = 0; j < cnt-1; j++)
            {
                if(tmp[j] == tmp[j+1]-1)
                    sub++;
            }
        }
    }
    sub = 2*sub;
    ans -= sub;
    printf("%I64d", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

long long n, k;
long long ans, sub;
long long tmp[100005];

int main()
{
   // freopen("text.inp", "rt", stdin);
    scanf("%I64d %I64d", &n, &k);
    ans = n-1;
    sub = 0;
    for(int i = 0; i < k; i++)
    {
        memset(tmp, 0, sizeof(tmp));
        long long cnt;
        scanf("%I64d", &cnt);
        ans += cnt-1;
        for(int j = 0; j < cnt; j++)
            scanf("%I64d", &tmp[j]);
        if(tmp[0] == 1)
        {
            for(int j = 0; j < cnt; j++)
            {
                if(tmp[j] == j+1)
                    sub++;
            }
        }
    }
    sub = 2*(sub-1);
    ans -= sub;
    printf("%I64d", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

long long n, k;
long long ans, sub;
long long tmp[100005];

int main()
{
   // freopen("text.inp", "rt", stdin);
    scanf("%I64d %I64d", &n, &k);
    ans = n-1;
    sub = 0;
    for(int i = 0; i < k; i++)
    {
        memset(tmp, 0, sizeof(tmp));
        long long cnt;
        scanf("%I64d", &cnt);
        ans += cnt-1;
        for(int j = 0; j < cnt; j++)
            scanf("%I64d", &tmp[j]);
        if(tmp[0] == 1)
        {
            for(int j = 0; j < cnt; j++)
            {
                if(tmp[j] == tmp[j+1]-1)
                    sub++;
            }
        }
    }
    sub = 2*sub;
    ans -= sub;
    printf("%I64d", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

long long n, k;
long long ans, sub;
long long tmp[100005];

int main()
{
    scanf("%I64d %I64d", &n, &k);
    ans = n-1;
    sub = 0;
    for(int i = 0; i < k; i++)
    {
        memset(tmp, 0, sizeof(tmp));
        long long cnt;
        scanf("%I64d", &cnt);
        ans += cnt-1;
        for(int j = 0; j < cnt; j++)
            scanf("%I64d", &tmp[j]);
        for(int j = 0; j < cnt; j++)
        {
            if(tmp[j] == tmp[j+1]-1)
                sub++;
        }
    }
    printf("%I64d", ans-2*sub);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

long long n, k;
long long ans, sub;
long long tmp[100005];

int main()
{
   // freopen("text.inp", "rt", stdin);
    scanf("%I64d %I64d", &n, &k);
    ans = n-1;
    sub = 0;
    for(int i = 0; i < k; i++)
    {
       // memset(tmp, 0, sizeof(tmp));
        long long cnt;
        scanf("%I64d", &cnt);
        ans += cnt-1;
        for(int j = 0; j < cnt; j++)
            scanf("%I64d", &tmp[j]);
        if(tmp[0] == 1)
        {
            for(int j = 0; j < cnt; j++)
            {
                if(tmp[j] == j+1)
                    sub++;
            }
        }
    }
    sub = 2*(sub-1);
    ans -= sub;
    printf("%I64d", ans);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

int n, k;
int ans, sub;
int tmp[100005];

int main()
{
    scanf("%d %d", &n, &k);
    ans = n-1;
    sub = 0;
    for(int i = 0; i < k; i++)
    {
        memset(tmp, 0, sizeof(tmp));
        int cnt;
        scanf("%d", &cnt);
        ans += cnt-1;
        for(int j = 0; j < cnt; j++)
            scanf("%d", &tmp[j]);
        for(int j = 0; j < cnt; j++)
        {
            if(tmp[j] == tmp[j+1]-1)
                sub++;
        }
    }
    printf("%d", ans-2*sub);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

long long n, k;
long long ans, sub;
long long tmp[100005];

int main()
{
   // freopen("text.inp", "rt", stdin);
    scanf("%I64d %I64d", &n, &k);
    ans = n-1;
    sub = 0;
    for(int i = 0; i < k; i++)
    {
       // memset(tmp, 0, sizeof(tmp));
        long long cnt;
        scanf("%I64d", &cnt);
        ans += cnt-1;
        for(int j = 0; j < cnt; j++)
            scanf("%I64d", &tmp[j]);
        if(tmp[0] == 1)
        {
            for(int j = 0; j < cnt; j++)
            {
                if(tmp[j] == tmp[j+1]-1)
                    sub++;
            }
        }
    }
    sub = 2*sub;
    ans -= sub;
    printf("%I64d", ans);
    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 100000 + 10;
int A[MAXN];
int N, M, K;
long long ans;
int main()
{
    while(scanf("%d%d", &N, &K)!=EOF)
    {
        ans = 0;
        int s = 0;
        for(int i=1; i<=K; i++)
        {
            scanf("%d", &M);
            for(int j=1;j<=M;j++)
            {
                int x;
                scanf("%d",&x);
                if(x == j) s++;
            }
        }
        if(s == 0) ans = (N - K) + N - 1;
        else ans = (N - s - K + 1) + (N - s );
        cout << ans <<endl;
    }
    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 100000 + 10;
int A[MAXN];
int N, M, K;
long long ans;
void solve()
{
    scanf("%d", &M);
    for(int i=1;i<=M;i++)
        scanf("%d", &A[i]);
    int tmp = 1, l = M - 1;
    while(A[l] + 1 == A[l+1] && l>= 1) {l--;tmp++;}
    ans += (M - tmp) * 2;
    ans += 1;
}
int main()
{
    while(scanf("%d%d", &N, &K)!=EOF)
    {
        ans = -1;
        for(int i=1;i<=K;i++)
            solve();
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 100000 + 10;
int A[MAXN];
int N, M, K;
long long ans;
void solve()
{
    scanf("%d", &M);
    for(int i=1; i<=M; i++)
        scanf("%d", &A[i]);
    int tmp = 1, l = M - 1;
    if(A[M] == N)
    {
        while(A[l] + 1 == A[l+1] && l>= 1)
        {
            l--;
            tmp++;
        }
        ans += (M - tmp) * 2;
        ans += 1;
    }
    else if(A[1] == 1 && A[M] == A[M])
    {
        ans += 1;
    }
    else
    {
        ans += (M - 1) * 2;
        ans += 1;
    }
}
int main()
{
    while(scanf("%d%d", &N, &K)!=EOF)
    {
        ans = -1;
        for(int i=1; i<=K; i++)
            solve();
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 100000 + 10;
int A[MAXN];
int N, M, K;
long long ans;
int main()
{
    while(scanf("%d%d", &N, &K)!=EOF)
    {
        ans = 0;
        int s = 0;
        for(int i=1; i<=K; i++)
        {
            scanf("%d", &M);
            for(int i=j;j<=M;j++)
            {
                int x;
                scanf("%d",&x);
                if(x == j) s++;
            }
        }
        if(s == 0) ans = (N - K) + N - 1;
        else ans = (N - s - K + 1) + (N - s );
        cout << ans <<endl;
    }
    return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 100000 + 10;
int A[MAXN];
int N, M, K;
long long ans;
int main()
{
    while(scanf("%d%d", &N, &K)!=EOF)
    {
        ans = 0;
        int s = 0;
        for(int i=1; i<=K; i++)
        {
            scanf("%d", &M);
            for(int i=1;i<=M;i++)
            {
                int x;
                scanf("%d",&x);
                if(x == i) s++;
            }
        }
        if(s == 0) ans = (N - K) + N - 1;
        else ans = (N - s - K + 1) + (N - s );
        cout << ans <<endl;
    }
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;
int m[maxn], a[maxn];

int main()
{
    int n, k, x;
    cin >> n >> k;
    int ans = 0;
    a[0] = 1e5;
    for(int i = 0; i < k; i++)
    {
        cin >> m[i];
        for(int j = 1; j <= m[i]; j++)
        {
            cin >> a[j];
            if(a[1] == 1 && a[j] - a[j-1] == 1)
                ans += 2;
        }
    }

    cout << n - k - ans + n - 1 - ans;
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;
int a[maxn];

int main()
{
    int n, m, k;
    cin >> n >> k;
    int ans = 0, cnt = 0;
    a[0] = 1e5;
    while(k--)
    {
        cin >> m;
        cnt += m - 1;
        for(int j = 1; j <= m; j++)
        {
            cin >> a[j];
            if(a[1] == 1 && a[j] - a[j-1] == 1)
                ans++;
        }
    }
    //cout << cnt << endl;
    cout << cnt - ans + n - 1 - ans;
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;
int a[maxn];

int main()
{
    int n, m, k;
    cin >> n >> k;
    int ans = 0;
    a[0] = 1e5;
    for(int i = 0; i < k; i++)
    {
        cin >> m;
        for(int j = 1; j <= m; j++)
        {
            cin >> a[j];
            if(a[1] == 1 && j > 1 && a[j] - a[j-1] == 1)
                ans++;
        }
    }
    //cout << n - k;
    cout << n - k - ans + n - 1 - ans;
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;
int a[maxn];

int main()
{
    int n, m, k;
    cin >> n >> k;
    int ans = 0, cnt;
    a[0] = 1e5;
    while(k--)
    {
        cin >> m;
        cnt += m - 1;
        for(int j = 1; j <= m; j++)
        {
            cin >> a[j];
            if(a[1] == 1 && a[j] - a[j-1] == 1)
                ans++;
        }
    }
    cout << cnt - ans + n - 1 - ans;
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;

int main()
{
    int n, k, ans = 0;
    cin >> n >> k;
    for(int i = 0; i < k; i++)
    {
        int m, x, t = 1;
        cin >> m;
        while(m--)
        {
            cin >> x;
            if(x == t) ans++, t++;
        }
    }
    cout << n - k - (ans - 1) + n - ans;
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;
int a[maxn];

int main()
{
    int n, m, k;
    cin >> n >> k;
    int ans = 0, cnt = 0;
    a[0] = 1e5;
    while(k--)
    {
        cin >> m;
        cnt += m - 1;
        for(int j = 1; j <= m; j++)
        {
            cin >> a[j];
            if(a[1] == 1 && a[j] - a[j-1] == 1)
                ans++;
        }
    }
    cout << cnt << endl;
    cout << cnt - ans + n - 1 - ans;
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int main()
{
    int n, k, sum = 0;
    cin >> n >> k;
    for(int i = 0; i < k; i++)
    {
        int m;
        cin >> m;
        for(int j = 0; j < m; j++)
            cin >> a[j];
        int no = 1;
        while(a[0] == 1 && no < m && a[no]- a[no-1] == 1)
            sum++, no++;
    }
    cout << n-k-sum+n-1-sum;
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;
int a[maxn];

int main()
{
    int n, m, k;
    cin >> n >> k;
    int ans = 0;
    a[0] = 1e5;
    while(k--)
    {
        cin >> m;
        for(int j = 1; j <= m; j++)
        {
            cin >> a[j];
            if(a[1] == 1 && j > 1 && a[j] - a[j-1] == 1)
                ans++;
        }
    }
    cout << n - k - ans + n - 1 - ans;
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int main()
{
    int n, k, sum = 0;
    cin >> n >> k;
    for(int i = 0; i < k; i++)
    {
        int m;
        cin >> m;
        for(int j = 0; j < m; j++)
        {
            cin >> a[j];
            if(a[0] == 1 && j > 0&& a[j]- a[j-1] ==1)
                sum++;
        }
    }
    cout << n-k-sum+n-1-sum;
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;
int a[maxn];

int main()
{
    int n, m, k, x;
    cin >> n >> k;
    int ans = 0;
    a[0] = 1e5;
    for(int i = 0; i < k; i++)
    {
        cin >> m;
        for(int j = 1; j <= m; j++)
        {
            cin >> a[j];
            if(a[1] == 1 && a[j] - a[j-1] == 1)
                ans++;
        }
    }

    cout << n - k - ans + n - 1 - ans;
    return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;

const int maxn = 1e5 + 10;
int m[maxn], a[maxn];

int main()
{
    int n, k, x;
    cin >> n >> k;
    int ans = 0;
    a[0] = 1e5;
    for(int i = 0; i < k; i++)
    {
        cin >> m[i];
        for(int j = 1; j <= m[i]; j++)
        {
            cin >> a[j];
            if(a[j] - a[j-1] > 1) ans++;
        }
    }
    //cout << ans << endl;
    if(n - k == ans) ans += n - 1;
    else ans += ans + k - 1;
    cout << ans ;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
    int n,k;
    cin>>n>>k;
    if(k==1)
    {
        cout<<0;
        return 0;
    }
    int timeToClose = 0;
    int timeToBreak = 0;
    for(int i =0;i < k; i++)
    {
        bool first = false;
        int m;
        cin>>m;
        int last;
        cin>>last;

        if(last==1)
            first=true;

        if(m==1)
            timeToClose++;
        for(int j =1;j < m; j++)
        {
            int curr;
            cin>>curr;

            if(curr>last+1)
            {
                if(first)
                    timeToClose += m-j;
                else
                    timeToClose += m;
                timeToBreak += m-j;
                for(int k = 0; k < m-j-1; k++)
                    cin>>curr;
                break;
            }
            if(j==m-1 && !first)
                timeToClose+=j;
            last = curr;
        }
    }
    cout<<timeToBreak+timeToClose;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
    int n,k;
    cin>>n>>k;
    int pieces = 0;
    int timeToBreak = 0;
    for(int i =0;i < k; i++)
    {
        int m;
        cin>>m;
        int last;
        cin>>last;
        if(m==1)
            pieces++;
        for(int j =1;j < m; j++)
        {
            int curr;
            cin>>curr;
            if(curr>last+1)
            {
                pieces += 1+m-j;
                timeToBreak += m-j;
                for(int k = 0; k < m-j-1; k++)
                    cin>>curr;
                break;
            }
            if(j==m-1)
                pieces++;
            last = curr;
        }
    }
    cout<<timeToBreak+pieces-1;
    return 0;
}