#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
  x = x < y ? x : y;
}
const int N = 300010, inf = 1e9;
int p[N], s[N], st[N], sz[N], v[N][2];
vector<int> tv[N];
pair<int, int> Find(int x) {
  if (p[x] == x) return {x, 0};
  int y = p[x];
  pair<int, int> ret = Find(y);
  return {ret.first, s[x] ^ ret.second};
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    st[i] = c - '0';
  }
  for (int i = 1; i <= m; i++) {
    int k, x;
    cin >> k;
    while (k--) cin >> x, tv[x].push_back(i);
  }
  for (int i = 1; i <= m; i++) p[i] = i, sz[i] = 1, v[i][1] = 1;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!tv[i].size()) {
      cout << ans << '\n';
      continue;
    }
    if (tv[i].size() == 2) {
      int x = tv[i][0], y = tv[i][1];
      auto [tx, sx] = Find(x);
      auto [ty, sy] = Find(y);
      if (sz[tx] > sz[ty]) swap(tx, ty), swap(sx, sy);
      if (tx != ty) {
        p[tx] = ty, s[tx] = sx ^ sy ^ (!st[i]), sz[ty] += sz[tx];
        ans -= min(v[tx][0], v[tx][1]);
        ans -= min(v[ty][0], v[ty][1]);
        v[ty][0] = min(inf, v[ty][0] + v[tx][s[tx]]);
        v[ty][1] = min(inf, v[ty][1] + v[tx][!s[tx]]);
        ans += min(v[ty][0], v[ty][1]);
      }
    } else {
      int x = tv[i][0];
      auto [tx, sx] = Find(x);
      ans -= min(v[tx][0], v[tx][1]);
      v[tx][sx ^ st[i]] = inf;
      ans += min(v[tx][0], v[tx][1]);
    }
    cout << ans << '\n';
  }
  return 0;
}
