import java.util.*;

public class problemC {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int time = 0;

		int n = sc.nextInt();
		int c = sc.nextInt();
		boolean found = false;
		for (int i = 0; i < c; i++) {
			int m = sc.nextInt();
			if (!found) {
				int next = sc.nextInt();
				if (next == 1) {
					found = true;
					int[] chain = new int[m];
					chain[0] = 1;
					boolean chained = true;
					for (int j = 1; j < m; j++) {
						chain[j] = sc.nextInt();
						if (chain[j] - chain[j - 1] != 1 && chained) {
							time += 2 * (m - j) + 1;
							sc.nextLine();
							chained = false;
							break;

						}
					}
					if (chained) {
						time++;
					}

				} else {
					time += 2 * m - 1;
					sc.nextLine();
				}
			} else {
				time += 2 * m - 1;
				sc.nextLine();
			}

		}
		System.out.println(time - 1);

	}

}
