#coding: utf-8

def main():
    n, m = map(int , raw_input().split())
    ans = 0
    for i in range(m):
        s = map(int, raw_input().split())
        cnt, a = s[0], s[1:]
        if a[0] != 1:
            ans += cnt + cnt - 1
        else:
            for idx, val in enumerate(a):
                if idx != 0 and val != a[idx-1] + 1:
                    ans += (cnt - idx) << 1
                    break
    print ans
if __name__ == "__main__":
    main()