#include <bits/stdc++.h>
using namespace std;
const int N = 600000;
int b[N];
int s1[N];
int s2[N];
int globRes = 0;
int korz[N];
int xkorz[N];
int sz[N];
int force[N];
int isForce[N];
int c[N][2];
vector<pair<int, int>> g[N];
int getWyn(int v) {
  if (isForce[v])
    return c[v][1 ^ force[v]];
  else
    return min(c[v][0], c[v][1]);
}
void dfs(int v, int o, int k, int xk) {
  korz[v] = k;
  xkorz[v] = xk;
  for (auto it : g[v]) {
    if (it.first == o) continue;
    dfs(it.first, v, k, xk ^ it.second);
  }
  c[korz[v]][xkorz[v]]++;
  sz[korz[v]]++;
}
void addForce(int v, int f) {
  if (korz[v] != v) {
    return addForce(korz[v], f ^ xkorz[v]);
  }
  if (isForce[v]) return;
  isForce[v] = 1;
  force[v] = f;
  globRes -= min(c[v][0], c[v][1]);
  globRes += c[v][1 ^ force[v]];
}
void addEdge(int v1, int v2, int k) {
  if (korz[v1] == korz[v2]) return;
  int r1 = sz[korz[v1]], r2 = sz[korz[v2]];
  if (r1 < r2) {
    swap(v1, v2);
    swap(r1, r2);
  }
  globRes -= getWyn(korz[v1]);
  globRes -= getWyn(korz[v2]);
  int k1 = korz[v1], k2 = korz[v2];
  g[v1].push_back(make_pair(v2, k));
  g[v2].push_back(make_pair(v1, k));
  dfs(v2, v1, korz[v1], xkorz[v1] ^ k);
  if (isForce[k2] && !isForce[k1]) {
    isForce[k1] = 1;
    force[k1] = force[k2] ^ xkorz[k2];
  }
  globRes += getWyn(k1);
}
int dk;
void debug() {}
void solve() {
  int n, k;
  cin >> n >> k;
  dk = k;
  for (int i = 1; i <= n; i++) {
    char x;
    cin >> x;
    b[i] = x - '0';
  }
  for (int i = 1; i <= k; i++) {
    int c;
    cin >> c;
    for (int j = 0; j < c; j++) {
      int x;
      cin >> x;
      if (s1[x] == 0)
        s1[x] = i;
      else
        s2[x] = i;
    }
  }
  for (int i = 1; i <= k; i++) {
    c[i][0] = 1;
    korz[i] = i;
    sz[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (s1[i] != 0) {
      if (s2[i] == 0) {
        addForce(s1[i], 1 ^ b[i]);
      } else {
        addEdge(s1[i], s2[i], 1 ^ b[i]);
      }
    }
    debug();
    cout << globRes << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
