n, k = map(int, input().split())
matr = []
for _ in range(k):
	matr.append(list(map(int, input().split()))[1:])

maxSeq = 0
for i in matr:
	if i[0] == 1:
		for j in range(1, len(i)):
			if i[j] != j+1:
				maxSeq = j
				break
		else:
			maxSeq = len(i)
		break
m = n - maxSeq + 1
print(m-1  +  m-k)