#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long x = 0, f = 1;
  register char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
void wri(long long x) {
  write(x);
  putchar(' ');
}
void writeln(long long x) {
  write(x);
  putchar('\n');
}
const int maxn = 3e5 + 233;
int size[2][maxn], fa[maxn], val[maxn], last[maxn];
int ans = 0;
vector<int> vec[maxn];
int find(int x) {
  if (x != fa[x]) {
    int t = fa[x];
    fa[x] = find(fa[x]);
    val[x] ^= val[t];
  }
  return fa[x];
}
void merge(int x, int y, int t) {
  int px = find(x), py = find(y);
  if (px == py) return;
  t ^= val[x] ^ val[y];
  fa[py] = px;
  val[py] ^= t;
  if (last[py] != 2)
    ans -= size[last[py]][py];
  else
    ans -= min(size[0][py], size[1][py]);
  if (last[px] != 2)
    ans -= size[last[px]][px];
  else
    ans -= min(size[0][px], size[1][px]);
  size[t ^ 0][px] += size[0][py];
  size[t ^ 1][px] += size[1][py];
  if (last[px] == 2 && last[py] != 2) last[px] = last[py] ^ val[py];
  if (last[px] != 2)
    ans += size[last[px]][px];
  else
    ans += min(size[0][px], size[1][px]);
}
void turn(int x, int t) {
  int px = find(x);
  t ^= val[x];
  if (last[px] == 2) {
    ans -= min(size[0][px], size[1][px]);
    ans += size[t][px];
    last[px] = t;
  }
}
int n, k;
char s[maxn];
int main() {
  n = read(), k = read();
  scanf("%s", s + 1);
  for (register int i = (1); i <= int(k); ++i) {
    int x = read();
    while (x--) vec[read()].push_back(i);
  }
  for (register int i = (1); i <= int(k); ++i) {
    fa[i] = i;
    val[i] = 0;
    size[0][i] = 0;
    size[1][i] = 1;
    last[i] = 2;
  }
  ans = 0;
  for (register int i = (1); i <= int(n); ++i) {
    if (vec[i].size() == 0) {
      assert(s[i] == '1');
    } else if (vec[i].size() == 1) {
      turn(vec[i][0], 1 ^ (s[i] - '0'));
    } else {
      assert(vec[i].size() == 2);
      merge(vec[i][0], vec[i][1], (s[i] - '0') ^ 1);
    }
    writeln(ans);
  }
  return 0;
}
