//package caseOfMatryoshkas;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class CaseOfMatryoshkas {

	public static void main(String [] args) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String [] parts = br.readLine().split(" ");
		int numMatryoshkas = Integer.parseInt(parts[0]);
		int numChanis = Integer.parseInt(parts[1]);


		int res = 0;

		if (numChanis==1){
			System.out.println(res);
			return;
		}

		ArrayList<int []> listMs = new ArrayList();
		int minArr [] = new int [1];
		minArr[0]=Integer.MAX_VALUE;
		for (int i=0;i<numChanis;i++){
			//System.out.println(res);
			parts = br.readLine().split(" ");
			int ms [] = new int[parts.length-1];
			for(int j=0;j<ms.length;j++){
				ms[j]=Integer.parseInt(parts[j+1]);
			}

			
			if (minArr[0]>ms[0]){
				res+=minArr.length-1;
				if (minArr[0]!=Integer.MAX_VALUE)
					listMs.add(minArr);

				minArr=ms;
			}
			else{
				listMs.add(ms);
				res+=ms.length-1;
			}
		}

		//System.out.println(res);
		int minV = Integer.MAX_VALUE;
		for (int [] ar : listMs){
			minV=Math.min(ar[0],minV);
		}

		int counter=0;
		for(int k : minArr){
			if (k>minV)
				break;
			counter++;
		}
		res+=minArr.length-counter;

		res+=numMatryoshkas-counter;

		System.out.println(res);
	}
}
