import java.io.PrintWriter;
import java.util.*;
public class b 
{
	public static void main(String[] arg)
	{
		new b();
	}
	public b()
	{
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int k = in.nextInt();
		PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
		int answer = 0;
		for(int i = 0; i < k; i++)
		{
			int size = in.nextInt();
			int[] arr = new int[size];
			for(int j = 0; j < size; j++) arr[j] = in.nextInt();
			int cur = arr[size-1];
			int temp = arr[size-1];
			for(int j = size-2; j >= 0; j--)
			{
				if(arr[j]+1 == temp)
				{
					temp--;
				}
				else
				{
					pq.add(cur);
					cur = arr[j];
					answer += size-j-1;
					size = j+1;
				}
			}
			pq.add(cur);
		}
		while(pq.size() > 1)
		{
			int temp = pq.poll();
			answer += pq.peek()-temp;
		}
		out.println(answer);
		
		in.close(); out.close();
	}
}
/*
4 2
2 2 1
2 3 4
*/