def root(x): if P[x] < 0: return x P[x] = root(P[x]) # 経路圧縮 return P[x] def unite(x, y): x = root(x) y = root(y) if x == y: return if x > y: x, y = y, x P[x] += P[y] P[y] = x def same(x, y): return root(x) == root(y) def size(x): x = root(x) return -P[x] N, M = map(int, input().split()) P = [-1] * N P1 = list(range(N)) for _ in range(M): t, *S = map(int, input().split()) s0 = P1[S[0] - 1] n = len(S) for i in reversed(range(n)): if i == 0: P1[S[(i + 1) % t] - 1] = s0 continue P1[S[(i + 1) % t] - 1] = P1[S[i] - 1] for i, p in enumerate(P1): unite(i, p) ans = 1 for i in range(N): if i == root(i): ans *= size(i) print(ans)