#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
int N, K, a[MAXN];
vector<int> V[MAXN];
char S[MAXN];
int f1[MAXN], v1[MAXN], f2[MAXN], chs[MAXN], ans;
int get1(int x) {
  if (f1[x] != x) f1[x] = get1(f1[x]);
  return f1[x];
}
void merge1(int x, int y) {
  x = get1(x), y = get1(y);
  if (x != y) f1[x] = y, v1[y] += v1[x];
}
int get2(int x) {
  if (f2[x] != x) f2[x] = get2(f2[x]);
  return f2[x];
}
inline int val(int x) {
  x = get2(x);
  if (chs[x] == 1)
    return v1[x];
  else if (chs[x] == 2)
    return v1[x + K];
  else
    return min(v1[x], v1[x + K]);
}
void merge2(int x, int y, int k) {
  if (get2(x) != get2(y)) {
    ans -= val(x) + val(y);
    int c = chs[get2(x)];
    f2[get2(x)] = get2(y);
    if (k == 1)
      merge1(x, y), merge1(x + K, y + K);
    else
      merge1(x, y + K), merge1(x + K, y);
    if (!chs[get2(y)] && c) {
      if (k == 1)
        chs[get2(y)] = c;
      else
        chs[get2(y)] = 3 - c;
    }
    ans += val(y);
  }
}
int main() {
  scanf("%d%d%s", &N, &K, S + 1);
  int i, j;
  for (i = 1; i <= K; ++i) {
    int c, x;
    scanf("%d", &c);
    while (c--) scanf("%d", &x), V[x].push_back(i);
  }
  for (i = 1; i <= K * 2; ++i) f1[i] = i, v1[i] = i > K;
  for (i = 1; i <= K; ++i) f2[i] = i;
  for (i = 1; i <= N; ++i) {
    if (V[i].size() == 1) {
      if (S[i] == '0')
        ans -= val(V[i][0]), chs[get2(V[i][0])] = 2, ans += val(V[i][0]);
      else
        ans -= val(V[i][0]), chs[get2(V[i][0])] = 1, ans += val(V[i][0]);
    } else if (V[i].size() == 2) {
      if (S[i] == '0')
        merge2(V[i][0], V[i][1], 2);
      else
        merge2(V[i][0], V[i][1], 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
