import java.io.*;
import java.util.HashMap;
import java.util.Scanner;

/**
 * Created by daria on 24.06.15.
 */
public class C {
    Scanner in;
    PrintWriter out;

    public void solve() throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();

        HashMap<Integer, Integer> chain = new HashMap<>();

        for (int i = 0; i < m; i++) {
            int k = in.nextInt();
            int l = in.nextInt();
            for (int j = 1; j < k; j++) {
                chain.put(l, l = in.nextInt());
            }
            chain.put(l, 0);
        }

        int time = 0;
        for (int i = 1; i < n; i++) {
            if (chain.get(i) != i + 1) {
                int k = i;
                while (chain.get(k) != 0) {
                    int l = chain.get(k);
                    chain.put(k, 0);
                    k = l;
                    time++;
                }
            }
            if (chain.containsKey(i + 1) && chain.get(i + 1) != 0) {
                int k = i + 1;
                while (chain.get(k) != 0) {
                    int l = chain.get(k);
                    chain.put(k, 0);
                    k = l;
                    time++;
                }
            }
            if (chain.get(i) != i + 1) {
                chain.put(i, i + 1);
                time++;
            }
            chain.put(i + 1, 0);
        }
        System.out.println(time);
    }

    public void run() {
        try {
            in = new Scanner(System.in);
            out = new PrintWriter(System.out);

            solve();

            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new C().run();
    }
}