import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
    static Main.MyScanner sc = new Main.MyScanner();
    // static Main.Parser sc = new Parser(System.in);
    static PrintWriter out = new PrintWriter(System.out, true);

    public static void main(String[] args) throws Exception {
        int n = sc.nextInt(), k = sc.nextInt() ;
        PriorityQueue<Stack<Integer>> q = new PriorityQueue<Stack<Integer>>(new Comparator<Stack<Integer>>() {

            @Override
            public int compare(Stack<Integer> o1, Stack<Integer> o2) {
                // TODO Auto-generated method stub
                return o1.peek() - o2.peek() ;
            }
        });
        for(int i = 0 ; i < k ; i++){
            int m = sc.nextInt() ;
            Stack a = new Stack<Integer>(),b = new Stack<Integer>() ;
            while(m-->0) a.push(sc.nextInt());
            while(!a.isEmpty()) b.push(a.pop()) ;
            q.add(b) ;
        }
        int ans = 0 ;
        while(!q.isEmpty()){
//          System.out.println(q);
            Stack<Integer> nowstack = q.remove() ;
//          System.out.println(nowstack);
            int nowint = nowstack.pop() ;
            if(!nowstack.isEmpty() && nowstack.peek()-1 == nowint){
                if(!nowstack.isEmpty())
                    q.add(nowstack) ;
                continue ;
            }
            ans += nowstack.size() ;
//          System.out.println(nowstack.size());
            while(!nowstack.isEmpty()){
                Stack<Integer> temp = new Stack<Integer>();
                temp.push(nowstack.pop());
                q.add(temp) ;
            }
            if(!q.isEmpty()){
                nowstack = q.remove() ;
//              System.out.println(nowstack);
//              nowint = nowstack.pop();
                ans += nowstack.size() - 1 ;
//              System.out.println(nowstack.size()-1);
                while(!nowstack.isEmpty()){
                    Stack<Integer> temp = new Stack<Integer>();
                    temp.push(nowstack.pop());
                    q.add(temp) ;
                }
                ans++;
            }
//          System.out.println(ans+" done "+q);
        }
        out.println(ans);
        
        out.close();
    }

    static private class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public int mod(long x) {
            return (int) x % 1000000007;
        }

        public int mod(int x) {
            return x % 1000000007;
        }

        boolean hasNext() {
            if (st.hasMoreElements())
                return true;
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
            return st.hasMoreTokens();
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

    static class Parser {
        final private int BUFFER_SIZE = 65536; // 2^16, a good compromise for
                                                // some problems
        private InputStream din; // Underlying input stream
        private byte[] buffer; // Self-maintained buffer
        private int bufferPointer; // Current read position in the buffer
        private int bytesRead; // Effective bytes in the buffer read from the
                                // input stream

        public Parser(InputStream in) {
            din = in;
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        /**
         * Read the next integer from the input stream.
         * 
         * @return The next integer.
         * @throws IOException
         */
        public int nextInt() throws IOException {
            int result = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            while (c >= '0' && c <= '9') {
                result = result * 10 + c - '0';
                c = read();
            }
            if (neg)
                return -result;
            return result;
        }

        /**
         * Read the next byte of data from the input stream.
         * 
         * @return the next byte of data, or -1 if the end of the stream is
         *         reached.
         * @throws IOException
         *             if an I/O error occurs.
         */
        public byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        /**
         * Read data from the input stream into the buffer
         * 
         * @throws IOException
         *             if an I/O error occurs.
         */
        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }
    }
}