#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
vector<int> g[300001];
vector<int> groups[300001];
bool color[300001];
int siz[300001];
int cnt[300001];
int par[300001];
bool noChange[300001];
bool inverse[300001];
int ans = 0;
int findp(int p) {
  if (par[p] == p) return p;
  return par[p] = findp(par[p]);
}
void unite(int px, int py, bool edge) {
  px = findp(px);
  py = findp(py);
  if (px == py) return;
  if (siz[py] < siz[px]) {
    swap(px, py);
  }
  if (edge) {
    if (!noChange[px]) {
      ans -= cnt[px];
      cnt[px] = siz[px] - cnt[px];
      ans += cnt[px];
      inverse[px] ^= 1;
    } else {
      ans -= cnt[py];
      cnt[py] = siz[py] - cnt[py];
      ans += cnt[py];
      inverse[py] ^= 1;
    }
  }
  if (inverse[px] ^ inverse[py]) {
    for (int i : groups[px]) {
      color[i] ^= 1;
    }
  }
  cnt[py] += cnt[px];
  noChange[py] |= noChange[px];
  for (int i : groups[px]) {
    groups[py].push_back(i);
  }
  siz[py] += siz[px];
  par[px] = py;
  if (!noChange[py] && siz[py] - cnt[py] < cnt[py]) {
    ans -= cnt[py];
    cnt[py] = siz[py] - cnt[py];
    inverse[py] ^= 1;
    ans += cnt[py];
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  s.insert(s.begin(), '0');
  for (int i = 0; i < k; i++) {
    int c;
    cin >> c;
    for (int j = 0; j < c; j++) {
      int x;
      cin >> x;
      g[x].push_back(i);
    }
    groups[i].push_back(i);
    par[i] = i;
    siz[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (g[i].size() == 1) {
      int x = g[i][0];
      int px = findp(g[i][0]);
      if ((s[i] - '0') ^ color[x] ^ inverse[px] == 0) {
        ans -= cnt[px];
        cnt[px] = siz[px] - cnt[px];
        ans += cnt[px];
        inverse[px] ^= 1;
      }
      noChange[px] = 1;
    } else if (g[i].size() == 2) {
      bool edge = 0;
      int x = g[i][0];
      int y = g[i][1];
      int px = findp(g[i][0]);
      int py = findp(g[i][1]);
      if ((s[i] - '0') ^ color[x] ^ inverse[px] ^ color[y] ^ inverse[py] == 0) {
        edge = 1;
      }
      unite(x, y, edge);
    }
    cout << ans << '\n';
  }
}
