import java.util.ArrayList;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int k = in.nextInt();
        List<Integer>[] l = new List[k];
        int ans = 0;
        int count = 0;
        int part = 0;
        for (int i = 0; i < k; i++) {
            l[i] = new ArrayList<>();
            int m = in.nextInt();
            for (int j = 0; j < m; j++) {
                l[i].add(in.nextInt());
            }
        }

        for (int i = 0; i < k; i++) {

            if (l[i].get(0) == 1) {
                for (int j = 0; j < l[i].size() - 1; j++) {
                    if (l[i].get(j + 1) - l[i].get(j) != 1) {
                        part = n - (j + 2);
                        count = n - (j + 1);
                        break;
                    }
                    if (j + 1 == l[i].size() - 1 && l[i].get(j + 1) - l[i].get(j) == 1) {
                        part = n - (j + 2);
                        count = n - (j + 2);
                    }
                }
            }
        }
        out.println(count + part - 1);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

}

