import sys

S = map(int, sys.stdin.readline().split())
n = S[0]
k = S[1]

moves = 0

for _ in range(k):
	S = map(int, sys.stdin.readline().split())
	if S[1] == 1:
		correct = 0
		for i in range(1, len(S)):
			if i == S[i]:
				correct += 1
			else:
				break
		moves += S[0]-correct
		moves += n-correct
	else:
		moves += S[0]-1

print moves