import java.util.Scanner;

/**
 * Created by aitch_nu on 9/9/15.
 */
public class CaseOfMatryoshkas {

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int count = 0;
        int cost = 0;
        for(int i=0;i<k;i++){
            int m = sc.nextInt();
            boolean broken = false;
            int pvs = sc.nextInt();
            count = count + 1;
            for(int j=1;j<m;j++){
                int current = sc.nextInt();
                if((pvs + 1) != current){
                    broken = true;
                }
                if(broken){
                    count++;
                    cost++;
                }
                pvs = current;
            }
        }
        System.out.println(cost + count -1);
    }
}
