import static java.lang.Math.*; 

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

public class Main {
	BufferedReader in; 
	PrintWriter out;
	StringTokenizer st; 

	String next() {
		while (st==null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(in.readLine());
			} catch (Exception e) {}
		}
		return st.nextToken(); 
	}

	int nextInt() {
		return Integer.parseInt(next()); 
	}

	long nextLong() {
		return Long.parseLong(next());
	}

	double nextDouble() {
		return Double.parseDouble(next());
	}

	public void run() throws Exception {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		int n = nextInt(), k = nextInt();
		int ans = 0;
		for (int i = 0; i < k; i++) {
			int m = nextInt();
			int m1 = nextInt();
			if (m1 == 1) {
				int k1 = 1;
				for (int j = 1; j < m; j++) {
					int m2 = nextInt();
					if (m2 == j + 1) k1 = m2;
				}
				ans += (m - k1) * 2;
			} else {
				for (int j = 1; j < m; j++) {
					int m2 = nextInt();
				}
				ans += (m - 1) + (m);
			}
		}
		out.println(ans);
		out.close(); 
 	}
	
	public static void main(String[] args) throws Exception {
		new Main().run(); 
	}

}