#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int t, i, p[N], e[N][2], g[N], a, j, f[N], ans, siz[N], n, k, m;
char c[N];
int Find(int x) { return f[x] ? f[x] = Find(f[x]) : x; }
void uniot(int x, int y) {
  int u = Find(x), v = Find(y);
  if (u != v) {
    f[u] = v;
    siz[v] += siz[u];
    if (p[v] == 0) p[v] = p[u];
  }
}
int main() {
  scanf("%d %d", &n, &k);
  scanf("%s", c + 1);
  for (i = 1; i <= k; ++i) {
    scanf("%d", &m);
    for (j = 1; j <= m; ++j) {
      scanf("%d", &a);
      e[a][g[a]++] = i;
    }
  }
  for (i = 1; i <= k; ++i) siz[i] = 1;
  for (i = 1; i <= n; ++i)
    if (g[i] == 1) e[i][g[i]++] = k + 1;
  siz[k + 1] = 1 << 30;
  for (i = 1; i <= n; ++i) {
    if (c[i] == '1') {
      if (g[i] == 2) {
        if (Find(e[i][0]) == Find(e[i][1])) {
          printf("%d\n", ans);
          continue;
        }
        ans -= min(siz[Find(e[i][0])], siz[Find(p[Find(e[i][0])])]);
        ans -= min(siz[Find(e[i][1])], siz[Find(p[Find(e[i][1])])]);
        if (p[Find(e[i][0])] && p[Find(e[i][1])])
          uniot(p[Find(e[i][0])], p[Find(e[i][1])]);
        uniot(e[i][0], e[i][1]);
        ans += min(siz[Find(e[i][1])], siz[Find(p[Find(e[i][1])])]);
      }
    } else {
      if (g[i] == 2) {
        if (Find(e[i][0]) == Find(p[Find(e[i][1])])) {
          printf("%d\n", ans);
          continue;
        }
        ans -= min(siz[Find(e[i][0])], siz[Find(p[Find(e[i][0])])]);
        ans -= min(siz[Find(e[i][1])], siz[Find(p[Find(e[i][1])])]);
        int x = p[Find(e[i][0])], y = p[Find(e[i][1])];
        if (x) uniot(e[i][1], x);
        if (y) uniot(e[i][0], y);
        p[Find(e[i][0])] = e[i][1];
        p[Find(e[i][1])] = e[i][0];
        ans += min(siz[Find(e[i][0])], siz[Find(p[Find(e[i][0])])]);
      }
    }
    printf("%d\n", ans);
  }
}
