#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (1e5);
int fa[((600010) + 5)];
int val[((600010) + 5)];
char str[((600010) + 5)];
vector<int> g[((600010) + 5)];
int n, k;
int finds(int x) { return fa[x] = (fa[x] == x ? x : finds(fa[x])); }
int Min(int x) { return min(val[finds(x)], val[finds(x + k)]); }
void unq(int x, int y) {
  int fx = finds(x), fy = finds(y);
  if (fx != fy) {
    fa[fx] = fy;
    val[fy] += val[fx];
  }
}
int main() {
  scanf("%d%d", &n, &k);
  scanf("%s", str + 1);
  for (int i = 1; i <= k; i++) {
    int m;
    scanf("%d", &m);
    for (int j = 1; j <= m; j++) {
      int x;
      scanf("%d", &x);
      g[x].push_back(i);
    }
  }
  int bgp = k * 2 + 1;
  for (int i = 1; i <= k * 2 + 1; i++) {
    fa[i] = i;
    val[i] = (i <= k);
  }
  val[bgp] = INF;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (g[i].size() == 1) {
      int a = g[i][0];
      int x = a + k * (str[i] == '0');
      ans -= Min(a);
      unq(x, bgp);
      ans += Min(a);
    } else if (g[i].size() == 2) {
      int a = g[i][0], b = g[i][1];
      if (str[i] == '1' && finds(a) != finds(b)) {
        ans -= (Min(a) + Min(b));
        unq(a, b);
        unq(a + k, b + k);
        ans += Min(a);
      }
      if (str[i] == '0' && finds(a) != finds(b + k)) {
        ans -= (Min(a) + Min(b));
        unq(a, b + k);
        unq(b, a + k);
        ans += Min(a);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
