#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 600050;
int n, k;
char s[maxn];
int fa[maxn], v[maxn];
vector<int> ve[maxn];
int getfa(int u) {
  if (u == fa[u]) return u;
  return fa[u] = getfa(fa[u]);
}
void uni(int x, int y) {
  int fx = getfa(x);
  int fy = getfa(y);
  if (fx != fy) {
    fa[fx] = fy;
    v[fy] += v[fx];
  }
}
int gmin(int x) { return min(v[getfa(x)], v[getfa(x + k)]); }
int main() {
  scanf("%d%d", &n, &k);
  scanf("%s", s + 1);
  for (int i = 1; i <= k; i++) {
    int t, x;
    scanf("%d", &t);
    while (t--) {
      scanf("%d", &x);
      ve[x].push_back(i);
    }
  }
  for (int i = 1; i <= 2 * k + 1; i++) {
    fa[i] = i;
    v[i] = (i <= k);
  }
  int big = 2 * k + 1;
  v[big] = 1e9;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (ve[i].size() == 1) {
      int tmp = ve[i][0] + k * (s[i] == '0');
      ans -= gmin(ve[i][0]);
      uni(tmp, big);
      ans += gmin(ve[i][0]);
    } else if (ve[i].size() == 2) {
      int x = ve[i][0], y = ve[i][1];
      if (s[i] == '0' && getfa(x) != getfa(y + k)) {
        ans -= (gmin(x) + gmin(y));
        uni(x, y + k);
        uni(y, x + k);
        ans += gmin(x);
      }
      if (s[i] == '1' && getfa(x) != getfa(y)) {
        ans -= (gmin(x) + gmin(y));
        uni(x, y);
        uni(y + k, x + k);
        ans += gmin(x);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
