import java.io.*;
import java.util.*;
public class Main {
    static BufferedReader br;
    static PrintWriter ou;
    static StringBuilder sb;
    
    public static void solve()throws IOException {
        String[] pts = br.readLine().split(" ");
        int n = Integer.parseInt(pts[0]);
        int k = Integer.parseInt(pts[1]);
        int ans = 0;
        int[] arr = new int[n + 1];
        int[] rev = new int[n + 1];
        for (int i = 0; i < k; i ++) {
            pts = br.readLine().split(" ");
            int num = Integer.parseInt(pts[0]);
            for (int j = num; j > 1; j --) {
                int x = Integer.parseInt(pts[j]);
                int y = Integer.parseInt(pts[j-1]);
                if (x != y + 1) {
                    ans ++;
                }
                else {
                    arr[y] = x;
                    rev[x] = y;
                }
            }
        }
        //sb.append(ans+"\n");
        for (int i = 1; i < n; i ++) {
            if(arr[i] == i + 1)
                ;//continue;
            else {
                int x = i + 1;
                int cnt = 0;
                while(arr[x] == x + 1) {
                    cnt++;
                    x++;
                }
                ans += (2 * cnt) + 1;
                i = x;
                if(i < n)   i--;
            }
            //sb.append(ans+"\n");
        }
        sb.append(ans);
    }
    public static void main(String[] args)throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        ou = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        sb = new StringBuilder("");
        
        int t = 1;//Integer.parseInt(br.readLine());
        while(t-- > 0) {
            solve();
        }
        ou.print(sb.toString());
        ou.close();
    }
}