import java.math.*;
import java.io.*;
import java.util.*;
public class C556C{
   public static int sum;
   public static int[] ar;
   public static void main(String[] args) throws IOException{
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
      String[] a1=br.readLine().split(" ");
      int n=Integer.parseInt(a1[0]);
      int k=Integer.parseInt(a1[1]);
      int nChains=k;
      sum=0;
      
      for(int x=0;x<k;x++){
         String[] s=br.readLine().split(" ");
         int m=Integer.parseInt(s[0]);
         if(Integer.parseInt(s[1])==1){
         for(int y=1;y<m;y++)
            if(Integer.parseInt(s[y])+1!=Integer.parseInt(s[y+1])){
               sum+=m-y;
               nChains+=m-y;
               break;
            }
            }
            else{
               sum+=m-1;
               nChains+=m-1;
            }
      }
      System.out.println(sum+nChains-1);
      
   }
}