n, c = map(int, raw_input().split())
dTime = 0
pieces = []
for i in xrange(c):
  arr = map(int, raw_input().split())
  if arr[1] == 1:
    ind = 1
    while ind + 1 < len(arr) and arr[ind + 1] - arr[ind] == 1:
      ind += 1
    p = len(arr[1:]) - (ind - 1)
    dTime += (p-1)
    pieces.extend(range(p))
  else:
    p = len(arr[1:])
    dTime += (p-1)
    pieces.extend(list(arr[1:]))
print dTime + len(pieces) - 1 
