import sys


def seq_len(arr):
    i = 0
    for i in xrange(1, len(arr)):
        if arr[i - 1] != i or arr[i] != i + 1:
            return i - 1
    else:
        return i

n, k = map(int, sys.stdin.readline().split())

arrs = []

for i in xrange(k):
    arrs.append(map(int, sys.stdin.readline().split())[1:])

parts = 0
dis = 0

for arr in arrs:
    s = seq_len(arr)
    d = len(arr) - (s + 1)
    p = len(arr) - s
    dis += d
    parts += p

sys.stdout.write(str(parts + dis - 1) + '\n')
