#include <bits/stdc++.h>
using namespace std;
const int mac = 3e5 + 10;
int n, k, lamp[mac][2];
int father[mac], num[mac][2], ans = 0, col[mac];
char s[mac];
int find(int x) {
  if (x == father[x]) return x;
  int tmp = find(father[x]);
  col[x] ^= col[father[x]];
  return father[x] = tmp;
}
void solve(int id, int tp) {
  if (id == 0)
    ans += tp * num[0][1];
  else
    ans += tp * min(num[id][1], num[id][0]);
}
void merge(int a, int b, int tp) {
  int fa = find(a), fb = find(b);
  tp = tp ^ col[a] ^ col[b];
  if (fa == fb) return;
  if (fa > fb) swap(fa, fb);
  solve(fa, -1);
  solve(fb, -1);
  num[fa][0] += num[fb][0 ^ tp];
  num[fa][1] += num[fb][1 ^ tp];
  solve(fa, 1);
  father[fb] = fa;
  col[fb] = tp;
}
int main() {
  scanf("%d%d", &n, &k);
  scanf("%s", s + 1);
  for (int i = 1; i <= k; i++) {
    int p;
    scanf("%d", &p);
    while (p--) {
      int x;
      scanf("%d", &x);
      if (lamp[x][0] == 0)
        lamp[x][0] = i;
      else
        lamp[x][1] = i;
    }
  }
  for (int i = 0; i <= k; i++) {
    num[i][0] = 1;
    father[i] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (s[i] == '1')
      merge(lamp[i][0], lamp[i][1], 0);
    else
      merge(lamp[i][0], lamp[i][1], 1);
    printf("%d\n", ans);
  }
  return 0;
}
