import java.util.Scanner;
import java.util.Arrays;
import java.lang.String;
import java.math.BigInteger;


  
public class JavaApplication1 {


    


//    static int v(int a){
//      return result;
//    }
    


    public static void main(String[] args) {
  
        
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int k = sc.nextInt(); 
        int nos = 0;
        int[] mi = new int[k+1];
        for(int i = 1; i <= k; i++)
        {
          mi[i] = sc.nextInt();
          int t = sc.nextInt();
          if(t != 1)
          {
            nos += 2*mi[i] - 1;
            for(int j = 1;j <= mi[i] - 1; j++)
              sc.nextInt();
          }
          else
          {
            int w = 1;
            for(int j = 1; j <= mi[i] - 1; j++)
            {
              if (sc.nextInt() != (w + 1))
              {
                for(int u = 1; u <= mi[i] - w - 1; u++)
                  sc.nextInt();
                break;
              }
              w++;
            }
            nos += 2*(mi[i] - w);
 

          }
        }
        System.out.println(nos);
//        int[] x = new int[n+1];

//        var = myfunction(123,234);
     
//        System.out.println(maxx);

   }
}