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 start = 0;
			while(start < arr.length-1 && arr[start]+1 == arr[start+1]) start++;
			for(int j = start; j < arr.length; j++)
			{
				pq.add(arr[j]);
				if(j != start)
					answer += 1;
			}
		}
		while(pq.size() > 1)
		{
			int temp = pq.poll();
			answer += pq.peek()-temp;
			answer += pq.peek()-temp-1;
		}
		out.println(answer);
		
		in.close(); out.close();
	}
}
/*
4 2
2 2 1
2 3 4
*/