#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll z = 0;
const string Alp = "abcdefghijklmnopqrstuvwxyz";
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> K(M);
  vector<vector<int>> vec(M, vector<int>(10));
  vector<vector<char>> c(M, vector<char>(10));
  vector<int> p(M);
  for (int i = 0; i < M; i++) {
    cin >> K[i];
    for (int j = 0; j < K[i]; j++) {
      cin >> vec[i][j];
      for (int l = 0; l < 10; l++) {
        if (vec[i][j] == l + 1) c[i][j] = Alp[l];
      }
    }
    cin >> p[i];
  }
  int ans = 0;
  for (int a = 0; a < 2; a++) {
    int x = 1;
    int sum = 0;
    for (int b = 0; b < 2; b++) {
      for (int c = 0; c < 2; c++) {
        for (int d = 0; d < 2; d++) {
          for (int e = 0; e < 2; e++) {
            for (int f = 0; f < 2; f++) {
              for (int g = 0; g < 2; g++) {
                for (int h = 0; h < 2; h++) {
                  for (int i = 0; i < 2; i++) {
                    for (int j = 0; j < 2; j++) {
                      for (int k = 0; k < M; k++) {
                        for (int l = 0; l < K[k]; i++) {
                          sum += Alp[l];
                        }
                        if (Alp[k] % 2 != p[k]) x = 0;
                      }
                      if (x == 1) ans++;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}
