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());

        int min = 0;
        ArrayList<Pair> pairs = new ArrayList<Pair>();
        ArrayList<Integer> nested = new ArrayList<Integer>();

        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) != nested.get(j + 1) - 1) {
                    Pair pair = new Pair(nested.get(j + 1), end);
                    pairs.add(pair);

                    end = nested.get(j);

                    min++;
                }
            }
            min--;
        }

        Collections.sort(pairs, comparator);
        int l = pairs.size();

        for (int i = 0; i < l; i++) {
            System.out.println(pairs.get(i).start + " " + pairs.get(i).end);
        }

        Pair req = new Pair(pairs.get(0).start, pairs.get(0).end);
        for (int i = 1; i < l; i++) {
            if (req.end == pairs.get(i).start - 1) {
                req.end = pairs.get(i).end;
                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;
        }
    };
}
