#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 4e5;
ll par[N], xr[N], cnt[N][2], fix[N];
ll ones = 0;
ll ocmp(ll v) {
  assert(v == par[v]);
  if (fix[v] != -1) {
    return cnt[v][1 ^ fix[v]];
  } else {
    return min(cnt[v][0], cnt[v][1]);
  }
}
pair<ll, ll> dsu(ll v) {
  if (v != par[v]) {
    auto res = dsu(par[v]);
    par[v] = res.first;
    xr[v] ^= res.second;
  }
  return {par[v], xr[v]};
}
void edge(ll v, ll u, ll w) {
  auto vres = dsu(v);
  auto ures = dsu(u);
  if (vres.first == ures.first) {
    assert(w == (vres.second ^ ures.second));
    return;
  }
  ones -= ocmp(vres.first) + ocmp(ures.first);
  par[vres.first] = ures.first;
  ll e = vres.second ^ ures.second ^ w;
  xr[vres.first] = e;
  cnt[ures.first][0] += cnt[vres.first][e];
  cnt[ures.first][1] += cnt[vres.first][e ^ 1];
  if (fix[vres.first] != -1) {
    assert(fix[ures.first] == -1 || fix[ures.first] == (fix[vres.first] ^ e));
    fix[ures.first] = fix[vres.first] ^ e;
  }
  ones += ocmp(ures.first);
}
void ass(ll v, ll w) {
  auto vres = dsu(v);
  ones -= ocmp(vres.first);
  ll value = w ^ vres.second;
  assert(fix[vres.first] == -1 || fix[vres.first] == value);
  fix[vres.first] = value;
  ones += ocmp(vres.first);
}
ll n, k;
string s;
vector<ll> g[N];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  iota(par, par + N, 0);
  fill_n(fix, N, -1);
  for (ll i = 0; i < N; ++i) {
    cnt[i][0] = 1;
  }
  cin >> n >> k >> s;
  for (ll first, c, i = 0; i < k; ++i) {
    cin >> c;
    while (c--) {
      cin >> first;
      g[first - 1].push_back(i);
    }
  }
  for (ll i = 0; i < n; ++i) {
    bool on = s[i] == '1';
    if (g[i].empty()) {
      ;
    } else if (g[i].size() == 1) {
      ass(g[i][0], !on);
    } else {
      assert(g[i].size() == 2);
      edge(g[i][0], g[i][1], !on);
    }
    cout << ones << "\n";
  }
  return 0;
}
