#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10, MAX = 3e4 + 5, MAXM = 4e5 + 5, BOUND = 2e5,
          MOD = 998244353, INF = 0x3f3f3f3f, base = 10000;
const long long INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-9;
struct node {
  int l, r, xo;
  node(int _l = 0, int _r = 0, int _xo = 0) : l(_l), r(_r), xo(_xo) {}
  int get() { return min(l, r); }
  void operator+=(node rhs) {
    l = min(INF, l + rhs.l);
    r = min(INF, r + rhs.r);
  }
} val[MAXN];
int n, k, fa[MAXN];
char s[MAXN];
vector<int> G[MAXN];
pair<int, int> find(int x) {
  if (fa[x] < 0) {
    return {x, 0};
  }
  pair<int, int> tmp = find(fa[x]);
  fa[x] = tmp.first;
  val[x].xo ^= tmp.second;
  return {fa[x], val[x].xo};
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  cin >> (s + 1);
  for (int i = 1; i <= k; i++) {
    fa[i] = -1;
    val[i] = {1, 0, 0};
    int num, c;
    cin >> num;
    while (num--) {
      cin >> c;
      G[c].push_back(i);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int tye = (s[i] - '0') ^ 1;
    if (ans == -1) {
      cout << ans << '\n';
      continue;
    }
    if (G[i].size() == 1) {
      pair<int, int> u = find(G[i][0]);
      ans -= val[u.first].get();
      val[u.first] += node((u.second == tye) * INF, (u.second != tye) * INF);
      ans += val[u.first].get();
    } else if (G[i].size() == 2) {
      pair<int, int> u = find(G[i][0]), v = find(G[i][1]);
      if (u.first == v.first) {
        cout << ans << '\n';
        continue;
      }
      ans -= val[u.first].get() + val[v.first].get();
      if (fa[u.first] > fa[v.first]) swap(u, v);
      if (u.second ^ v.second ^ tye) {
        swap(val[v.first].l, val[v.first].r);
        val[v.first].xo = 1;
      }
      fa[u.first] += fa[v.first];
      fa[v.first] = u.first;
      val[u.first] += val[v.first];
      ans += val[u.first].get();
    }
    cout << ans << '\n';
  }
  return 0;
}
