n, k = map(int, raw_input().split())
a = []
for line in xrange(k):
    a.append([int(item) for item in raw_input().split()])

count = 0
for i in xrange(k):
    if a[i][1]!=1:
        count += a[i][0]-1
    else:
        if a[i][0]>1:
            j = 2
            while j<=a[i][0] and a[i][j]==j:
                j+=1
            count += a[i][0]-j+1
count = count*2+k-1
print count