import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Reader in = new Reader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskC {
    public void solve(int testNumber, Reader in, PrintWriter out) {
        int m=in.nextInt();
        int n=in.nextInt();
        ArrayList<ArrayList<Integer>> arrs=new ArrayList<ArrayList<Integer>>();
        int arrOne=0;
        int onePos=0;
        for(int i=0;i<n;i++) arrs.add(new ArrayList<Integer>());
        for(int i=0;i<n;i++){
            int num=in.nextInt();
            for(int j=0;j<num;++j) {
                int temp = in.nextInt();
                if (temp==1){
                    arrOne=i;
                    onePos=j;
                }
                arrs.get(i).add(temp);
            }
        }

        int ordered=1;
        for(int i=onePos+1;i<arrs.get(arrOne).size();++i){
            if (arrs.get(arrOne).get(i)==1+ordered) ordered++;
        }

        int maxtime=0;
        for(int i=0;i<n;i++){
            maxtime+=arrs.get(i).size()-1;
        }

        int res=maxtime-(ordered-1)+m-1-(ordered-1);
        out.println(res);
    }
}

class Reader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public Reader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
}
