import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;

public class C {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st;

        st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken()), m = Integer.parseInt(st.nextToken());
        ArrayList<Integer> nested = new ArrayList<Integer>();

        int min = Integer.MAX_VALUE, count = 0;
        ArrayList<Pair> pairs = new ArrayList<Pair>();

        for (int i = 0, l; i < m; i++) {
            st = new StringTokenizer(br.readLine());
            l = Integer.parseInt(st.nextToken());

            nested.clear();
            nested.add(-10);

            for (int j = 0; j < l; j++) {
                nested.add(Integer.parseInt(st.nextToken()));
            }

            int end = nested.get(l);
            for (int j = l - 1; j > -1; j--) {
                if (nested.get(j) + 1 != nested.get(j + 1)) {
                    pairs.add(new Pair(nested.get(j + 1), end));
                    end = nested.get(j);
                    count++;
                }
            }
            count--;
        }

        Collections.sort(pairs, comparator);
        int l = pairs.size();
        ArrayList<Pair> dolls = new ArrayList<Pair>();

        Pair current = pairs.get(0);
        for (int i = 1; i < l; i++) {
            if (pairs.get(i).start == pairs.get(i).end && pairs.get(i).start == current.end + 1) {
                current.end++;
                count++;
            } else {
                dolls.add(current);
                current = pairs.get(i);
            }
        }
        dolls.add(current);

        /*for (Pair pair : dolls) {
            System.out.println(pair.start + " " + pair.end);
        }
        System.out.println(count);*/

        l = dolls.size();
        int sumRemove = 0, sumNest = 0;
        ArrayList<Integer> remove = new ArrayList<Integer>();
        ArrayList<Integer> nest = new ArrayList<Integer>();
        for (int i = 0; i < l; i++) {
            remove.add(dolls.get(i).end - dolls.get(i).start);
            sumRemove += remove.get(i);

            nest.add(remove.get(i) + 1);
            sumNest += nest.get(i);
        }

        for (int i = 0; i < l; i++) {
            int temp = count + (sumRemove - remove.get(i)) + (sumNest - nest.get(i));
            min = Math.min(temp, min);
        }

        out.println(min);
        out.close();
    }

    private static class Pair {
        int start;
        int end;

        public Pair(int start, int end) {
            this.start = start;
            this.end = end;
        }
    }

    private static Comparator<Pair> comparator = new Comparator<Pair>() {
        @Override
        public int compare(Pair o1, Pair o2) {
            return o1.start - o2.start;
        }
    };
}
