n, k = map(int, input().split())

arr = []
for i in range(k):
	arr.append([int(x) for x in input().split()][1:])

ans = 0
rozobrane = []
for row in arr:
	tmp = 0
	for i in range(len(row)-1):
		if row[i] != row[i+1] - 1:
			tmp += 1

	rozobrane.append(tmp)

#print(rozobrane)
print(sum(rozobrane) * 2 + k - 1)