import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;


public class R310Div2C {

	public static void main(String[] args) {
		FastScanner in=new FastScanner();
		int n=in.nextInt();
		int k=in.nextInt();
		ArrayList<ArrayList<Integer>> a=new ArrayList<ArrayList<Integer>>();
		int[] m=new int[k];
		for(int i=0;i<k;i++){
			a.add(new ArrayList<Integer>());
			m[i]=in.nextInt();
			for(int j=0;j<m[i];j++)
				a.get(i).add(in.nextInt());
		}
		
		int brk=0;
		int k1=0;
		HashSet<Integer> set=new HashSet<Integer>();
		for(int i=0;i<k;i++){
			for(int j=0;j<m[i];j++){
				for(k1=j;k1<m[i];k1++)
					if(a.get(i).get(k1)-a.get(i).get(j)>k1-j)
						break;
				
				brk++;

				if(a.get(i).get(j)>1)
					set.add(a.get(i).get(j));
				j=k1-1;
			}
			brk--;
		}
		System.out.println(brk+set.size());
	}
	static class FastScanner{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(){br=new BufferedReader(new InputStreamReader(System.in));}
		String nextToken(){
			while(st==null||!st.hasMoreElements())
				try{st=new StringTokenizer(br.readLine());}catch(Exception e){}
			return st.nextToken();
		}
		int nextInt(){return Integer.parseInt(nextToken());}
		long nextLong(){return Long.parseLong(nextToken());}
		double nextDouble(){return Double.parseDouble(nextToken());}
	}
}
