#include <bits/stdc++.h>
using namespace std;
int dset[333333], ssize[333333], res[333333][2], type[333333];
pair<int, int> fa(int a) {
  int x = 0;
  while (dset[a] != a) x ^= type[a], a = dset[a];
  return {a, x};
}
int r = 0;
void merge(int a, int b, int t) {
  pair<int, int> p1 = fa(a), p2 = fa(b);
  if (p1.first == p2.first) return;
  if (ssize[p1.first] > ssize[p2.first]) swap(p1, p2);
  r -= min(res[p1.first][0], res[p1.first][1]);
  r -= min(res[p2.first][0], res[p2.first][1]);
  dset[p1.first] = p2.first;
  type[p1.first] = p1.second ^ p2.second ^ t;
  res[p2.first][0] += res[p1.first][p1.second ^ p2.second ^ t];
  res[p2.first][1] += res[p1.first][p1.second ^ p2.second ^ t ^ 1];
  r += min(res[p2.first][0], res[p2.first][1]);
  ssize[p2.first] += ssize[p1.first];
}
const int inf = 1e9 + 7;
vector<int> v[333333];
char s[333333];
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 1; i < x + 3; i++)
    dset[i] = i, ssize[i] = 1, res[i][0] = 0, res[i][1] = 1;
  res[x + 1][1] = inf, res[x + 2][0] = inf, res[x + 2][1] = 0;
  scanf("%s", s);
  for (int i = 1; i < x + 1; i++) {
    int t, a;
    scanf("%d", &t);
    for (int j = 1; j < t + 1; j++) scanf("%d", &a), v[a - 1].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      if (v[i].size() == 1)
        merge(x + 1, v[i][0], 0);
      else if (v[i].size() == 2)
        merge(v[i][0], v[i][1], 0);
    } else {
      if (v[i].size() == 1)
        merge(x + 2, v[i][0], 0);
      else if (v[i].size() == 2)
        merge(v[i][0], v[i][1], 1);
    }
    printf("%d\n", r);
  }
}
