#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, k, ans;
int pre[N];
char str[N];
int p[N], s[N][2];
int d[N], type[N];
vector<int> F[N];
int find(int x) {
  if (x == pre[x]) return x;
  int y = pre[x];
  pre[x] = find(pre[x]);
  d[x] = (d[x] + d[y]) & 1;
  return pre[x];
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%1d", &p[i]);
  for (int i = 1; i <= k; i++) pre[i] = i, s[i][0] = 1, type[i] = -1;
  ans = 0;
  for (int i = 1, m, x; i <= k; i++) {
    scanf("%d", &m);
    for (int j = 1; j <= m; j++) {
      scanf("%d", &x);
      F[x].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (F[i].size() == 1) {
      int x = F[i][0], y = find(x);
      if (type[y] == -1) {
        ans -= min(s[y][0], s[y][1]);
        if ((d[x] + !p[i]) & 1) {
          type[y] = 1;
          swap(s[y][0], s[y][1]);
          ans += s[y][1];
        } else {
          type[y] = 0;
          ans += s[y][1];
        }
      }
    } else if (F[i].size() == 2) {
      int x = F[i][0], y = F[i][1], u = find(x), v = find(y);
      if (u != v) {
        if (type[u] == -1)
          ans -= min(s[u][0], s[u][1]);
        else
          ans -= s[u][1];
        if (type[v] == -1)
          ans -= min(s[v][0], s[v][1]);
        else
          ans -= s[v][1];
        pre[u] = v;
        d[u] = (d[x] + d[y] + !p[i]) & 1;
        if (type[v] != -1 && type[u] == -1) {
          type[u] = (type[v] + d[u]) & 1;
          if (type[u] == 1) swap(s[u][0], s[u][1]);
        }
        if (type[u] != -1 && type[v] == -1) {
          type[v] = (type[u] + d[u]) & 1;
          if (type[v] == 1) swap(s[v][0], s[v][1]);
        }
        if (type[u] != -1) {
          s[v][0] += s[u][0];
          s[v][1] += s[u][1];
        } else {
          s[v][0] += s[u][d[u]];
          s[v][1] += s[u][!d[u]];
        }
        if (type[v] == -1)
          ans += min(s[v][0], s[v][1]);
        else
          ans += s[v][1];
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
