
import java.util.*;
import java.io.*;

public class CaseofMatryoshkas {

	// https://codeforces.com/contest/556/problem/C
	
	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("CaseofMatryoshkas"));

		StringTokenizer st = new StringTokenizer(in.readLine());
		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		ArrayList<ArrayList<Integer>> beg = new ArrayList<>();
		for (int i=0; i<k; i++) {
			st = new StringTokenizer(in.readLine());
			int curnum = Integer.parseInt(st.nextToken());
			ArrayList<Integer> cur = new ArrayList<>();
			for (int j=0; j<curnum; j++) {
				cur.add(Integer.parseInt(st.nextToken()));
			}
			beg.add(cur);
		}
		
		int count=0;
		int available=0;
		for (int i=0; i<k; i++) {
			int cur=beg.get(i).get(beg.get(i).size()-1);
			for (int j=beg.get(i).size()-2; j>=0; j--) {
				if (beg.get(i).get(j) != cur-1) {
					// indices 0, 1, ... , j are available
					available+= j+1;
					count+= j+1;
					break;
				}
				else {
					cur = beg.get(i).get(j);
				}
			}
			available++;
		}
		
		count += available-1;
		System.out.println(count);
		
	}
}

// consec = dont separate