#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  bool flg = false;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') flg = true;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
  return flg ? -x : x;
}
int n, m;
vector<int> e[300010];
char str[300010];
int f[300010], w[300010], s[2][300010], t[300010];
int find(int x) {
  if (!f[x]) return x;
  int t = f[x];
  f[x] = find(f[x]);
  w[x] ^= w[t];
  return f[x];
}
int ans;
int getval(int x) {
  if (!~t[x]) return min(s[0][x], s[1][x]);
  return s[t[x] ^ 1][x];
}
void merge(int x, int y, int q) {
  f[y] = x, w[y] = q, s[0][x] += s[q][y], s[1][x] += s[q ^ 1][y];
  if (~t[y]) t[x] = t[y] ^ q;
}
void work(int o, vector<int> E) {
  if (E.empty()) return;
  if (E.size() == 1) {
    int x = E[0];
    int y = find(x);
    ans -= getval(y);
    t[y] = o ^ 1 ^ w[x];
    ans += getval(y);
    return;
  }
  int x = E[0], y = E[1];
  int a = find(x), b = find(y);
  if (a == b) return;
  ans -= getval(a), ans -= getval(b);
  merge(a, b, w[y] ^ o ^ 1 ^ w[x]);
  ans += getval(a);
}
void solve() {
  n = read(), m = read();
  scanf("%s", str + 1);
  for (int i(1), _i(m); i <= _i; i++) {
    int t = read();
    while (t--) e[read()].push_back(i);
  }
  for (int i(1), _i(m); i <= _i; i++) s[0][i] = 1;
  memset(t, -1, sizeof t);
  for (int i(1), _i(n); i <= _i; i++) {
    work(str[i] - '0', e[i]);
    printf("%d\n", ans);
  }
}
int main() {
  for (int T = 1; T--;) solve();
  return 0;
}
