import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),k = sc.nextInt();
        int ans = 0;
        for(int i = 1;i <= k;i++) {
            int x = sc.nextInt();
            int sum = 0,q;
            boolean tag = true;
            for(int j = 1;j <= x;j++) {
                q = sc.nextInt();
                if(tag == true && q == j) {
                    sum++;
                } else {
                    tag = false;
                }
            }
            if(sum == 0) {
                ans += 2 * x - 1;
            } else {
                int res = x - sum + 1;
                ans += 2 * (res - 1);
            }
        }
        System.out.println(ans);
    }
}