#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > sw(n + 1, {-1, -1}), sz(k + 1, {1, 0});
  vector<int> fa(k + 1), dis(k + 1), st(n + 1);
  iota(fa.begin(), fa.end(), 0);
  string ch;
  cin >> ch;
  for (int i = 0; i <= n - 1; i++) st[i + 1] = ch[i] == '0';
  for (int i = 1; i <= k; i++) {
    int c, x;
    cin >> c;
    for (int j = 1; j <= c; j++) {
      cin >> x;
      if (sw[x].first == -1)
        sw[x].first = i;
      else if (sw[x].second == -1)
        sw[x].second = i;
      else
        assert(0);
    }
  }
  int ans = 0;
  function<int(int)> getfa = [&](int x) {
    if (x == fa[x]) return x;
    int f = getfa(fa[x]);
    dis[x] ^= dis[fa[x]];
    return fa[x] = f;
  };
  auto calc = [&](int x, int flag) {
    if (x == 0)
      ans += sz[x].second * flag;
    else
      ans += min(sz[x].first, sz[x].second) * flag;
  };
  auto merge = [&](int x, int y, int w) {
    int p = getfa(x), q = getfa(y);
    if (p == q) {
      assert((dis[x] ^ dis[y]) == w);
      return;
    }
    calc(p, -1);
    calc(q, -1);
    if (q == 0) swap(p, q);
    fa[q] = p, dis[q] = w ^ dis[x] ^ dis[y];
    if (dis[q])
      sz[p] = {sz[p].first + sz[q].second, sz[p].second + sz[q].first};
    else
      sz[p] = {sz[p].first + sz[q].first, sz[p].second + sz[q].second};
    sz[q] = {0, 0};
    calc(p, 1);
  };
  for (int i = 1; i <= n; i++) {
    if (sw[i].first == -1) {
      cout << ans << "\n";
      continue;
    }
    if (sw[i].second == -1) {
      merge(0, sw[i].first, st[i]);
    } else {
      merge(sw[i].first, sw[i].second, st[i]);
    }
    cout << ans << "\n";
  }
}
