#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100;
const int Mod = 998244353;
int n, m;
int fac[Maxn + 5];
struct PQ_Tree {
  int n;
  struct node {
    std::vector<int> son;
    int type, op;
  } t[Maxn << 1 | 5];
  int tot, rt;
  bool OK;
  std::bitset<Maxn + 5> vis;
  void init(int _n) {
    tot = n = _n;
    rt = ++tot;
    for (int i = 1; i <= n; i++) {
      t[rt].son.push_back(i);
    }
  }
  void dfs_1(int u) {
    if (u <= n) {
      t[u].op = vis[u] ? 2 : 1;
      return;
    }
    t[u].op = 0;
    for (int i = 0; i < (int)t[u].son.size(); i++) {
      int v = t[u].son[i];
      dfs_1(v);
      t[u].op |= t[v].op;
    }
  }
  void dfs_2(int u, int lim) {
    if (!OK || t[u].op != 3) {
      return;
    }
    std::vector<int> a[4];
    for (int i = 0; i < (int)t[u].son.size(); i++) {
      int v = t[u].son[i];
      a[t[v].op].push_back(v);
    }
    if ((lim > 0) + a[3].size() >= 3) {
      OK = 0;
    }
    if (lim == 0 && (a[2].size() + a[3].size()) <= 1) {
      if (!a[2].empty()) {
        dfs_2(a[2][0], 0);
      }
      if (!a[3].empty()) {
        dfs_2(a[3][0], 0);
      }
      return;
    }
    if (t[u].type) {
      int now = 0;
      std::vector<int> S;
      if (t[t[u].son[0]].op == 2 || t[t[u].son.back()].op == 1) {
        std::reverse(t[u].son.begin(), t[u].son.end());
      }
      for (int i = 0; i < (int)t[u].son.size(); i++) {
        int v = t[u].son[i];
        if (t[v].op == 1) {
          S.push_back(v);
          now += (now == 1);
        } else if (t[v].op == 2) {
          S.push_back(v);
          now += (now == 0);
          if (now == 2) {
            OK = 0;
          }
        } else {
          if (now == 2) {
            OK = 0;
          }
          now++;
          dfs_2(v, 3 - now);
          S.insert(S.end(), t[v].son.begin(), t[v].son.end());
        }
      }
      if (lim > 0 && now == 2) {
        OK = 0;
      }
      if (lim == 1) {
        std::reverse(S.begin(), S.end());
      }
      t[u].son = S;
    } else {
      int z = -1;
      if (a[2].size() == 1) {
        z = a[2][0];
      } else if (a[2].size() > 1) {
        z = ++tot;
        t[z].type = 0;
        t[z].son = a[2];
      }
      std::vector<int> S;
      if (!a[3].empty()) {
        dfs_2(a[3][0], 2);
        S.insert(S.end(), t[a[3][0]].son.begin(), t[a[3][0]].son.end());
      }
      if (z != -1) {
        S.push_back(z);
      }
      if (a[3].size() > 1) {
        dfs_2(a[3][1], 1);
        S.insert(S.end(), t[a[3][1]].son.begin(), t[a[3][1]].son.end());
      }
      if (a[1].empty()) {
        if (lim == 1) {
          std::reverse(S.begin(), S.end());
        }
        t[u].type = 1;
        t[u].son = S;
      } else {
        if (lim) {
          t[u].son.clear();
          t[u].type = 1;
          z = a[1][0];
          if (a[1].size() > 1) {
            z = ++tot;
            t[z].type = 0;
            t[z].son = a[1];
          }
          t[u].son.push_back(z);
          t[u].son.insert(t[u].son.end(), S.begin(), S.end());
          if (lim == 1) {
            std::reverse(t[u].son.begin(), t[u].son.end());
          }
        } else {
          z = S[0];
          if (S.size() > 1) {
            z = ++tot;
            t[z].son = S;
            t[z].type = 1;
          }
          t[u].son = a[1];
          t[u].son.push_back(z);
        }
      }
    }
  }
  bool insert(const std::bitset<Maxn + 5> &B) {
    vis = B;
    dfs_1(rt);
    OK = 1;
    dfs_2(rt, 0);
    return OK;
  }
  int calc(int u) {
    if (u <= n) {
      return 1;
    }
    int ans = t[u].type ? 2 : fac[t[u].son.size()];
    for (int i = 0; i < (int)t[u].son.size(); i++) {
      int v = t[u].son[i];
      ans = 1ll * ans * calc(v) % Mod;
    }
    return ans;
  }
} T;
int main() {
  scanf("%d%d", &n, &m);
  fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = 1ll * fac[i - 1] * i % Mod;
  }
  T.init(n);
  while (m--) {
    static std::bitset<Maxn + 5> B;
    B.reset();
    int k;
    scanf("%d", &k);
    while (k--) {
      int a;
      scanf("%d", &a);
      B[a] = 1;
    }
    if (!T.insert(B)) {
      puts("0");
      return 0;
    }
  }
  printf("%d\n", T.calc(T.rt));
  return 0;
}

### Prompt

Generate a CPP solution to the following problem:

You are the organizer of the famous "Zurich Music Festival". There will be n singers who will perform at the festival, identified by the integers 1, 2, ..., n. You must choose in which order they are going to perform on stage. 

You have m friends and each of them has a set of favourite singers. More precisely, for each 1≤ i≤ m, the i-th friend likes singers s_{i,1},   s_{i, 2},   ..., \,s_{i, q_i}.

A friend of yours is happy if the singers he likes perform consecutively (in an arbitrary order). An ordering of the singers is valid if it makes all your friends happy.

Compute the number of valid orderings modulo 998 244 353.

Input

The first line contains two integers n and m (1≤ n,\,m≤ 100) — the number of singers and the number of friends correspondingly.

The i-th of the next m lines contains the integer q_i (1≤ q_i≤ n) — the number of favorite singers of the i-th friend – followed by the q_i integers s_{i,1},   s_{i, 2},   ..., \,s_{i, q_i} (1≤ s_{i,1}<s_{i,2}<⋅⋅⋅<s_{i,q_i}≤ n) — the indexes of his favorite singers.

Output

Print the number of valid orderings of the singers modulo 998 244 353.

Examples

Input


3 1
2 1 3


Output


4


Input


5 5
2 1 2
2 2 3
2 3 4
2 4 5
2 1 5


Output


0


Input


100 1
1 50


Output


35305197


Input


5 1
5 1 2 3 4 5


Output


120


Input


2 5
1 2
1 2
1 2
1 1
1 1


Output


2


Input


11 4
5 4 5 7 9 11
2 2 10
2 9 11
7 1 2 3 5 8 10 11


Output


384

Note

Explanation of the first sample: There are 3 singers and only 1 friend. The friend likes the two singers 1 and 3. Thus, the 4 valid orderings are: 

  * 1 3 2
  * 2 1 3
  * 2 3 1
  * 3 1 2



Explanation of the second sample: There are 5 singers and 5 friends. One can show that no ordering is valid.

Explanation of the third sample: There are 100 singers and only 1 friend. The friend likes only singer 50, hence all the 100! possible orderings are valid.

Explanation of the fourth sample: There are 5 singers and only 1 friend. The friend likes all the singers, hence all the 5!=120 possible orderings are valid.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100;
const int Mod = 998244353;
int n, m;
int fac[Maxn + 5];
struct PQ_Tree {
  int n;
  struct node {
    std::vector<int> son;
    int type, op;
  } t[Maxn << 1 | 5];
  int tot, rt;
  bool OK;
  std::bitset<Maxn + 5> vis;
  void init(int _n) {
    tot = n = _n;
    rt = ++tot;
    for (int i = 1; i <= n; i++) {
      t[rt].son.push_back(i);
    }
  }
  void dfs_1(int u) {
    if (u <= n) {
      t[u].op = vis[u] ? 2 : 1;
      return;
    }
    t[u].op = 0;
    for (int i = 0; i < (int)t[u].son.size(); i++) {
      int v = t[u].son[i];
      dfs_1(v);
      t[u].op |= t[v].op;
    }
  }
  void dfs_2(int u, int lim) {
    if (!OK || t[u].op != 3) {
      return;
    }
    std::vector<int> a[4];
    for (int i = 0; i < (int)t[u].son.size(); i++) {
      int v = t[u].son[i];
      a[t[v].op].push_back(v);
    }
    if ((lim > 0) + a[3].size() >= 3) {
      OK = 0;
    }
    if (lim == 0 && (a[2].size() + a[3].size()) <= 1) {
      if (!a[2].empty()) {
        dfs_2(a[2][0], 0);
      }
      if (!a[3].empty()) {
        dfs_2(a[3][0], 0);
      }
      return;
    }
    if (t[u].type) {
      int now = 0;
      std::vector<int> S;
      if (t[t[u].son[0]].op == 2 || t[t[u].son.back()].op == 1) {
        std::reverse(t[u].son.begin(), t[u].son.end());
      }
      for (int i = 0; i < (int)t[u].son.size(); i++) {
        int v = t[u].son[i];
        if (t[v].op == 1) {
          S.push_back(v);
          now += (now == 1);
        } else if (t[v].op == 2) {
          S.push_back(v);
          now += (now == 0);
          if (now == 2) {
            OK = 0;
          }
        } else {
          if (now == 2) {
            OK = 0;
          }
          now++;
          dfs_2(v, 3 - now);
          S.insert(S.end(), t[v].son.begin(), t[v].son.end());
        }
      }
      if (lim > 0 && now == 2) {
        OK = 0;
      }
      if (lim == 1) {
        std::reverse(S.begin(), S.end());
      }
      t[u].son = S;
    } else {
      int z = -1;
      if (a[2].size() == 1) {
        z = a[2][0];
      } else if (a[2].size() > 1) {
        z = ++tot;
        t[z].type = 0;
        t[z].son = a[2];
      }
      std::vector<int> S;
      if (!a[3].empty()) {
        dfs_2(a[3][0], 2);
        S.insert(S.end(), t[a[3][0]].son.begin(), t[a[3][0]].son.end());
      }
      if (z != -1) {
        S.push_back(z);
      }
      if (a[3].size() > 1) {
        dfs_2(a[3][1], 1);
        S.insert(S.end(), t[a[3][1]].son.begin(), t[a[3][1]].son.end());
      }
      if (a[1].empty()) {
        if (lim == 1) {
          std::reverse(S.begin(), S.end());
        }
        t[u].type = 1;
        t[u].son = S;
      } else {
        if (lim) {
          t[u].son.clear();
          t[u].type = 1;
          z = a[1][0];
          if (a[1].size() > 1) {
            z = ++tot;
            t[z].type = 0;
            t[z].son = a[1];
          }
          t[u].son.push_back(z);
          t[u].son.insert(t[u].son.end(), S.begin(), S.end());
          if (lim == 1) {
            std::reverse(t[u].son.begin(), t[u].son.end());
          }
        } else {
          z = S[0];
          if (S.size() > 1) {
            z = ++tot;
            t[z].son = S;
            t[z].type = 1;
          }
          t[u].son = a[1];
          t[u].son.push_back(z);
        }
      }
    }
  }
  bool insert(const std::bitset<Maxn + 5> &B) {
    vis = B;
    dfs_1(rt);
    OK = 1;
    dfs_2(rt, 0);
    return OK;
  }
  int calc(int u) {
    if (u <= n) {
      return 1;
    }
    int ans = t[u].type ? 2 : fac[t[u].son.size()];
    for (int i = 0; i < (int)t[u].son.size(); i++) {
      int v = t[u].son[i];
      ans = 1ll * ans * calc(v) % Mod;
    }
    return ans;
  }
} T;
int main() {
  scanf("%d%d", &n, &m);
  fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = 1ll * fac[i - 1] * i % Mod;
  }
  T.init(n);
  while (m--) {
    static std::bitset<Maxn + 5> B;
    B.reset();
    int k;
    scanf("%d", &k);
    while (k--) {
      int a;
      scanf("%d", &a);
      B[a] = 1;
    }
    if (!T.insert(B)) {
      puts("0");
      return 0;
    }
  }
  printf("%d\n", T.calc(T.rt));
  return 0;
}

```