inp = input().split()
n = int(inp[0])
k = int(inp[1])

out = 0
for i in range(0, k):
    inp = list(map(int, input().split()))
    
    for j in range(len(inp)-1, 0, -1):
        out += 1
        
        if(inp[j]==j):
            break
        
        out += 1 if (j>1) else 0
            
out -= 1
print(out)

'''
'''
