#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e6 + 555;
char ori[maxn];
vector<int> cnt[maxn];
int wei[maxn];
int fa[maxn];
inline int Fa(int x) {
  if (fa[x] == x) return x;
  fa[x] = Fa(fa[x]);
  return fa[x];
}
inline void union1(int a, int b) {
  int A = Fa(a);
  int B = Fa(b);
  if (A != B) {
    fa[A] = B;
    wei[B] += wei[A];
  }
}
int Wei(int a) { return wei[Fa(a)]; }
void solve() {
  int n, k;
  scanf("%d %d", &n, &k);
  scanf("%s", ori + 1);
  for (int i = 1; i <= k; i++) {
    int nn;
    scanf("%d", &nn);
    int aa;
    for (int j = 1; j <= nn; j++) {
      scanf("%d", &aa);
      cnt[aa].push_back(i);
    }
  }
  for (int i = 1; i <= k; i++) {
    fa[i * 2] = i * 2;
    fa[i * 2 + 1] = i * 2 + 1;
    wei[i * 2] = 0;
    wei[i * 2 + 1] = 1;
  }
  int T = k * 3;
  fa[T] = T;
  wei[T] = INT_MAX / 10;
  int len = strlen(ori + 1);
  int res = 0;
  for (int i = 1; i <= len; i++) {
    if (cnt[i].size() == 1) {
      if (ori[i] == '0') {
        res -= min(Wei(cnt[i][0] * 2 + 1), Wei(cnt[i][0] * 2));
        union1(cnt[i][0] * 2, T);
        res += Wei(cnt[i][0] * 2 + 1);
      } else {
        res -= min(Wei(cnt[i][0] * 2 + 1), Wei(cnt[i][0] * 2));
        union1(cnt[i][0] * 2 + 1, T);
        res += Wei(cnt[i][0] * 2);
      }
    } else if (cnt[i].size() == 2) {
      if (ori[i] == '0') {
        if (Fa(cnt[i][0] * 2) != Fa(cnt[i][1] * 2 + 1)) {
          res -= min(Wei(cnt[i][0] * 2), Wei(cnt[i][0] * 2 + 1));
          res -= min(Wei(cnt[i][1] * 2), Wei(cnt[i][1] * 2 + 1));
          union1(cnt[i][0] * 2, cnt[i][1] * 2 + 1);
          union1(cnt[i][1] * 2, cnt[i][0] * 2 + 1);
          res += min(Wei(cnt[i][1] * 2), Wei(cnt[i][1] * 2 + 1));
        }
      } else {
        if (Fa(cnt[i][0] * 2) != Fa(cnt[i][1] * 2)) {
          res -= min(Wei(cnt[i][0] * 2 + 1), Wei(cnt[i][0] * 2));
          res -= min(Wei(cnt[i][1] * 2), Wei(cnt[i][1] * 2 + 1));
          union1(cnt[i][0] * 2, cnt[i][1] * 2);
          union1(cnt[i][0] * 2 + 1, cnt[i][1] * 2 + 1);
          res += min(Wei(cnt[i][0] * 2), Wei(cnt[i][0] * 2 + 1));
        }
      }
    }
    printf("%d\n", res);
  }
}
signed main() { solve(); }
