#include #include typedef struct arr { int n; int *a; } arr; int cmp_arr (const void *ap, const void *bp) { arr a = *(arr *)ap; arr b = *(arr *)bp; int idx = 0; while (idx < a.n && idx < b.n) { if (a.a[idx] < b.a[idx]) { return -1; } if (a.a[idx] > b.a[idx]) { return 1; } return 0; } if (a.n < b.n) { return -1; } if (a.n > b.n) { return 1; } return 0; } long long power_mod (long long a, long long b, long long mod_num) { long long ans = 1LL; if (b > 0LL) { ans = power_mod(a, b/2LL, mod_num); ans = (ans * ans) % mod_num; if (b%2LL == 1LL) { ans = (ans *a) % mod_num; } } return ans; } int main () { int n = 0; int m = 0; int l = 0; int a = 0; int res = 0; int ans = 0; long long mod_num = 998244353LL; arr inc[1000] = {}; int work[1000000] = {}; res = scanf("%d", &n); res = scanf("%d", &m); for (int i = 0; i < n; i++) { inc[i].n = n; inc[i].a = work+(m*i); } for (int i = 0; i < m; i++) { res = scanf("%d", &l); for (int j = 0; j < l; j++) { res = scanf("%d", &a); a--; inc[a].a[i] = 1; } } qsort(inc, n, sizeof(arr), cmp_arr); ans = n; for (int i = 1; i < n; i++) { int is_ok = 1; for (int j = 0; j < m; j++) { if (inc[i-1].a[j] != inc[i].a[j]) { is_ok = 0; } } if (is_ok > 0) { ans--; } } printf("%lld\n", power_mod(2LL, (long long)ans, mod_num)); return 0; }