#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e5 + 7;
int n, k, fa[maxn], val[maxn], big;
char a[maxn];
vector<int> E[maxn];
int fid(int x) { return fa[x] == x ? x : fa[x] = fid(fa[x]); }
int uni(int x, int y) {
  int fx = fid(x), fy = fid(y);
  if (fx != fy) {
    fa[fx] = fy;
    val[fy] += val[fx];
  }
}
int gmin(int x) { return min(val[fid(x)], val[fid(x + k)]); }
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  cin >> (a + 1);
  for (int i = 1; i <= k; ++i) {
    int x, y;
    cin >> x;
    while (x--) {
      cin >> y;
      E[y].push_back(i);
    }
  }
  for (int i = 1; i <= 2 * k + 1; ++i) {
    fa[i] = i;
    val[i] = (i <= k);
  }
  big = 2 * k + 1;
  val[big] = 1e9;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (E[i].size() == 1) {
      int tmp = E[i][0] + k * (a[i] == '0');
      ans -= gmin(E[i][0]);
      uni(tmp, big);
      ans += gmin(E[i][0]);
    } else if (E[i].size() == 2) {
      int x = E[i][0], y = E[i][1];
      if (a[i] == '0' && fid(x) != fid(x + k)) {
        ans = ans - gmin(x) - gmin(y);
        uni(x, y + k);
        uni(y, x + k);
        ans += gmin(x);
      }
      if (a[i] == '1' && fid(x) != fid(y)) {
        ans = ans - gmin(x) - gmin(y);
        uni(x, y);
        uni(x + k, y + k);
        ans += gmin(x);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
