#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, k;
char str[N];
vector<int> occ[N];
int sz[N][2];
int p[N], c[N], len[N];
int ans = 0;
int f(int u) { return u == p[u] ? u : f(p[u]); }
int get(int u) { return u == p[u] ? 0 : c[u] ^ get(p[u]); }
void join(int a, int b, int dif) {
  dif ^= get(a) ^ get(b);
  a = f(a), b = f(b);
  if (a == b) return;
  if (len[a] > len[b]) swap(a, b);
  p[a] = b;
  c[a] = dif;
  len[b] += len[a];
  ans -= min(sz[a][0], sz[a][1]);
  ans -= min(sz[b][0], sz[b][1]);
  if (dif)
    sz[b][0] += sz[a][1], sz[b][1] += sz[a][0];
  else
    sz[b][0] += sz[a][0], sz[b][1] += sz[a][1];
  if (sz[b][0] > N) sz[b][0] = N;
  if (sz[a][0] > N) sz[a][0] = N;
  ans += min(sz[b][0], sz[b][1]);
}
int main() {
  scanf("%d %d %s", &n, &k, str);
  for (int i = 0; i < k; i++) {
    int clen;
    scanf("%d", &clen);
    while (clen--) {
      int id;
      scanf("%d", &id);
      occ[id - 1].push_back(i);
    }
  }
  for (int i = 0; i < k; i++) {
    p[i] = i;
    sz[i][0] = 1;
    len[i] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (str[i] == '1') {
      if ((int)occ[i].size() == 1) {
        int rep = f(occ[i][0]);
        ans -= min(sz[rep][0], sz[rep][1]);
        sz[rep][get(occ[i][0])] = N;
        ans += min(sz[rep][0], sz[rep][1]);
      } else if ((int)occ[i].size() == 2) {
        join(occ[i][0], occ[i][1], 0);
      }
    } else {
      if ((int)occ[i].size() == 1) {
        int rep = f(occ[i][0]);
        ans -= min(sz[rep][0], sz[rep][1]);
        sz[rep][!get(occ[i][0])] = N;
        ans += min(sz[rep][0], sz[rep][1]);
      } else if ((int)occ[i].size() == 2) {
        join(occ[i][0], occ[i][1], 1);
      }
    }
    printf("%d\n", ans);
  }
}
