
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<>();
		int firstindex=0;
		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()));
				if (cur.get(j) == 1) firstindex=i;
			}
			beg.add(cur);
		}
		
		int stop=-1;
		for (int j=1; j<beg.get(firstindex).size(); j++) {
			if (beg.get(firstindex).get(j) != j+1) {
				stop = j;
					// 0,1, ... , j-1
					// not good = j, j+1, ... , beg.get(firstindex).size()-1
				break;
			}
		}
		if (stop == -1) stop = beg.get(firstindex).size();
		
		int count=0;
		int available=0;
		for (int i=0; i<k; i++) {
			if (i == firstindex) {
				int j = beg.get(firstindex).size()-stop;
				available += j+1;
				count += j;
			}
			else {
				available += beg.get(i).size();
				count += beg.get(i).size()-1;
			}
		}
		
		count += available-1;
		System.out.println(count);
		
	}
}

/*
		int longestconsec = 1;
		int longestconsecindex=0;
		for (int i=0; i<k; i++) {
			int cur=beg.get(i).get(0);
			boolean did=false;
			for (int j=1; j<beg.get(i).size(); j++) {
				if (beg.get(i).get(j) != cur+1) {
					// indices 0, 1, ... , j-1 are consec 
					// indices j, j+1, j+2, ... , beg.get(i).size()-1   available
					if (j > longestconsec) {
						longestconsec= j;
						longestconsecindex=i;
					}
					did = true;
					break;
				}
				else {
					cur = beg.get(i).get(j);
				}
			}
			if (!did && beg.get(i).size() > longestconsec) {
				longestconsec=beg.get(i).size();
				longestconsecindex=i;
			}
		}
 */

/*
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);
*/