#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int ptr;
int ans = 0;
int par[N], cnt[N], real_cnt[N], one[N];
bool prop[N], fix[N];
int root(int u) {
  while (par[u] != u) {
    u = par[u];
  }
  return u;
}
int getcol(int u) {
  int ans = prop[u];
  while (par[u] != u) {
    u = par[u];
    ans ^= prop[u];
  }
  return ans;
}
void color(int u, int c, bool first) {
  int r = root(u);
  fix[r] |= first;
  if (getcol(u) == c) return;
  ans -= one[r];
  one[r] = real_cnt[r] - one[r];
  ans += one[r];
  prop[r] ^= 1;
}
void edge(int u, int v) {
  int ur = root(u);
  int vr = root(v);
  if (ur == vr) return;
  if (getcol(u) == getcol(v)) {
    int addu = real_cnt[ur] - 2 * one[ur];
    int addv = real_cnt[vr] - 2 * one[vr];
    if (!fix[ur] && (addu < addv || fix[vr])) {
      color(u, getcol(u) ^ 1, 0);
    } else {
      color(v, getcol(v) ^ 1, 0);
    }
  }
  if (cnt[ur] > cnt[vr]) swap(ur, vr);
  prop[ur] ^= prop[vr];
  par[ur] = vr;
  cnt[vr] += cnt[ur];
  real_cnt[vr] += real_cnt[ur];
  one[vr] += one[ur];
  fix[vr] |= fix[ur];
}
int n, k;
string second;
vector<int> in[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 0; i < N; ++i) {
    par[i] = i;
    cnt[i] = 1;
  }
  cin >> n >> k;
  cin >> second;
  for (int i = 0; i < k; ++i) {
    int cnt;
    cin >> cnt;
    for (int j = 0; j < cnt; ++j) {
      int e;
      cin >> e;
      --e;
      in[e].push_back(i);
    }
  }
  for (int i = 0; i < k; ++i) {
    real_cnt[i] = 1;
  }
  ptr = k;
  for (int i = 0; i < n; ++i) {
    if (in[i].empty()) {
    } else if (in[i].size() == 1) {
      if (second[i] == '1')
        color(in[i][0], 0, 1);
      else
        color(in[i][0], 1, 1);
    } else {
      if (second[i] == '1') {
        edge(ptr, in[i][0]);
        edge(ptr, in[i][1]);
        ++ptr;
      } else {
        edge(in[i][0], in[i][1]);
      }
    }
    cout << ans << '\n';
  }
}
