#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < (int)(m); i++) {
    int k;
    cin >> k;
    for (int j = 0; j < (int)(k); j++) {
      int s;
      cin >> s;
      s--;
      a[s] |= 1 << i;
    }
  }
  int p = 0;
  for (int i = 0; i < (int)(m); i++) {
    int P;
    cin >> P;
    p |= P << i;
  }
  cout << p << endl;
  int ct = 0;
  for (int i = 0; i < (int)(1 << n); i++) {
    int t = 0;
    for (int j = 0; j < (int)(n); j++) {
      if (i >> j & 1) t ^= a[j];
    }
    if (p == t) ct++;
  }
  cout << ct << endl;
}
