#include <bits/stdc++.h>
using namespace std;
const int MX = 300005;
int dsu_par[MX], col[MX];
pair<int, int> dsu_find(int v) {
  if (v == dsu_par[v]) return {v, 0};
  auto tmp = dsu_find(dsu_par[v]);
  dsu_par[v] = tmp.first;
  col[v] ^= tmp.second;
  return {tmp.first, col[v]};
}
long long left_size[MX], right_size[MX];
long long ans = 0;
char s[MX];
vector<int> comps[MX];
int main() {
  int n, k;
  ignore = scanf("%d %d", &n, &k);
  ignore = scanf(" %s", s + 1);
  for (int i = 1; i <= k; i++) {
    int c;
    ignore = scanf(" %d", &c);
    while (c--) {
      int x;
      ignore = scanf("%d", &x);
      comps[x].push_back(i);
    }
  }
  for (int i = 1; i <= k; i++) {
    dsu_par[i] = i;
    left_size[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (comps[i].size() == 1) {
      int x = comps[i][0];
      auto rt = dsu_find(x);
      ans -= min(left_size[rt.first], right_size[rt.first]);
      if ((s[i] == '0') == (rt.second == 0)) {
        right_size[rt.first] += MX;
      } else {
        left_size[rt.first] += MX;
      }
      ans += min(left_size[rt.first], right_size[rt.first]);
    } else if (comps[i].size() == 2) {
      int x = comps[i][0], y = comps[i][1];
      auto rt1 = dsu_find(x);
      auto rt2 = dsu_find(y);
      if (rt1.first != rt2.first) {
        ans -= min(left_size[rt1.first], right_size[rt1.first]);
        ans -= min(left_size[rt2.first], right_size[rt2.first]);
        if ((rt1.second == rt2.second) != (s[i] == '1')) {
          swap(left_size[rt1.first], right_size[rt1.first]);
        }
        left_size[rt2.first] += left_size[rt1.first];
        right_size[rt2.first] += right_size[rt1.first];
        dsu_par[rt1.first] = rt2.first;
        col[rt1.first] = rt1.second ^ rt2.second ^ (s[i] == '0');
        ans += min(left_size[rt2.first], right_size[rt2.first]);
      }
    }
    printf("%lld\n", ans);
  }
}
