#include <bits/stdc++.h>
using namespace std;
const int N = 300000;
int n, m, a[N + 9][2];
char str[N + 9];
int fa[N * 2 + 9], siz[N * 2 + 9], vis[N * 2 + 9], tag[N * 2 + 9], ans;
int H(int id, int k) { return id * m + k; }
int Query_fa(int k) { return k == fa[k] ? k : fa[k] = Query_fa(fa[k]); }
void Merge(int x, int y) {
  x = Query_fa(x);
  y = Query_fa(y);
  if (tag[x]) tag[x] = 0, ans -= siz[x];
  if (tag[y]) tag[y] = 0, ans -= siz[y];
  if (x == y) return;
  fa[x] = y;
  siz[y] += siz[x];
  vis[y] = vis[x] | vis[y];
}
void Erase(int x) {
  x = Query_fa(x);
  if (tag[x]) tag[x] = 0, ans -= siz[x];
  vis[x] = 1;
}
int main() {
  scanf("%d%d%s", &n, &m, str + 1);
  for (int i = 1; i <= m; ++i) {
    int sk;
    scanf("%d", &sk);
    for (int j = 1; j <= sk; ++j) {
      int x;
      scanf("%d", &x);
      a[x][(bool)a[x][0]] = i;
    }
  }
  for (int i = 0; i < 2; ++i)
    for (int j = 1; j <= m; ++j) {
      int t = H(i, j);
      fa[t] = t;
      siz[t] = i;
      if (!i) tag[t] = 1;
    }
  for (int i = 1; i <= n; ++i) {
    if (str[i] - '0') {
      if (a[i][1]) {
        Merge(H(0, a[i][0]), H(0, a[i][1]));
        Merge(H(1, a[i][0]), H(1, a[i][1]));
        int x = Query_fa(H(0, a[i][0])), y = Query_fa(H(1, a[i][0]));
        if (vis[y] || !vis[x] && siz[x] < siz[y])
          tag[x] = 1, ans += siz[x];
        else
          tag[y] = 1, ans += siz[y];
      } else if (a[i][0]) {
        Erase(H(1, a[i][0]));
        int x = Query_fa(H(0, a[i][0]));
        if (!tag[x]) tag[x] = 1, ans += siz[x];
      }
    } else {
      if (a[i][1]) {
        Merge(H(0, a[i][0]), H(1, a[i][1]));
        Merge(H(1, a[i][0]), H(0, a[i][1]));
        int x = Query_fa(H(0, a[i][0])), y = Query_fa(H(1, a[i][0]));
        if (vis[y] || !vis[x] && siz[x] < siz[y])
          tag[x] = 1, ans += siz[x];
        else
          tag[y] = 1, ans += siz[y];
      } else if (a[i][0]) {
        Erase(H(0, a[i][0]));
        int x = Query_fa(H(1, a[i][0]));
        if (!tag[x]) tag[x] = 1, ans += siz[x];
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
