#include <bits/stdc++.h>
using namespace std;
const int NN = 300005;
char s[NN];
int n, t, ans;
int fa[NN * 2], c, x, k, u, v, l[NN], r[NN];
long long val[NN * 2];
int find(int x) {
  if (fa[x] != x) fa[x] = find(fa[x]);
  return fa[x];
}
void merge(int x, int y) {
  int xx = find(x);
  int yy = find(y);
  if (xx == yy) return;
  fa[xx] = yy;
  val[yy] += val[xx];
}
int cal(int x) { return min(val[find(x)], val[find(x + k)]); }
int main() {
  scanf("%d%d", &n, &k);
  scanf("%s", s + 1);
  for (int i = 1; i <= k * 2; i++) fa[i] = i;
  for (int i = 1; i <= k; i++) {
    scanf("%d", &c);
    for (int j = 1; j <= c; j++) {
      scanf("%d", &x);
      if (l[x] == 0)
        l[x] = i;
      else
        r[x] = i;
    }
  }
  ans = 0;
  for (int i = 1; i <= k; i++) val[i] = 1;
  fa[0] = 0;
  val[0] = 0x7fffffff;
  for (int i = 1; i <= n; i++) {
    if (r[i] == 0) {
      u = l[i];
      if (u != 0) {
        ans -= cal(u);
        if (s[i] == '1') {
          merge(u, 0);
        } else {
          merge(u + k, 0);
        }
        ans += cal(u);
      }
    } else {
      u = l[i];
      v = r[i];
      if (s[i] == '1') {
        if (find(u) != find(v)) {
          ans -= cal(u);
          ans -= cal(v);
          merge(u, v);
          merge(u + k, v + k);
          ans += cal(u);
        }
      } else {
        if (find(u) != find(v + k)) {
          ans -= cal(u);
          ans -= cal(v);
          merge(u, v + k);
          merge(v, u + k);
          ans += cal(u);
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
