def main():
    n, k = [int(t) for t in input().split()]

    bind = [False for _ in range(n - 1)]

    for _ in range(k):
        a = [int(t) for t in input().split()]
        for i in range(1, len(a) - 1):
            if a[i] + 1 == a[i + 1]:
                bind[i] = True

    cost = 0
    continuous = True
    for bond in bind:
        if continuous:
            if not bond:
                cost += 1
        else:
            if bond:
                cost += 2
            else:
                cost += 1

    print(cost)


if __name__ == '__main__':
    main()