using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); var map = NArr(m); var sets = new Bitset[m]; var ans = 2L; var mod = 998_244_353; for (var i = 0; i < m; ++i) { sets[i] = new Bitset(n); if (!map[i].Skip(1).Contains(1)) { for (var j = 0; j < n; ++j) sets[i].Set(j, true); foreach (var ai in map[i].Skip(1)) sets[i].Set(ai, false); } else { foreach (var ai in map[i].Skip(1)) sets[i].Set(ai, true); } } for (var i = 0; i < m; ++i) { if (map[i][0] != 0 && map[i][0] != n) { var or = new Bitset(n); for (var j = 0; j < m; ++j) { if (i != j && sets[i].Includes(sets[j])) or.Or(sets[j]); } if (!or.Equals(sets[i])) ans = ans * 2 % mod; } } WriteLine(ans); } class Bitset { int _length; ulong[] data; public Bitset(int length) { _length = length; data = new ulong[(length + 63) / 64]; } public void Set(int pos, bool val) { if (!val) data[pos / 64] = (data[pos / 64] ^ ((ulong)1 << (pos % 64))); else data[pos / 64] = (data[pos / 64] | ((ulong)1 << (pos % 64))); } public void Or(Bitset b) { for (var i = 0; i < data.Length; ++i) data[i] = data[i] | b.data[i]; } public bool Includes(Bitset b) { for (var i = 0; i < data.Length; ++i) if ((data[i] | b.data[i]) != data[i]) return false; return true; } public bool Equals(Bitset b) { for (var i = 0; i < data.Length; ++i) if (data[i] != b.data[i]) return false; return true; } public bool[] Expand() { var ans = new bool[_length]; for (var i = 0; i < _length; ++i) ans[i] = (data[i / 64] >> (i % 64)) % 2 == 1; return ans; } } }