n,k = map(int, raw_input().strip().split(' '))

a = []
discount = 0
asscount = 0
for i in range(0,k):
  b = map(int,raw_input().strip().split(' '))
  print b
  if b[1] == 1:
    d = 1
    while(d <= b[0] and d == b[d]):
      d += 1
    print b[0]
    discount += b[0] - d + 1
    asscount += b[0] - d + 2
    print asscount, discount
    continue
  if b[0] == 1:
    asscount += 1
    print asscount, discount
    continue
  else:
    asscount += b[0]
    discount += b[0] - 1
    print asscount, discount

print (asscount + discount - 1)