#include <bits/stdc++.h>
using namespace std;
int N, M, K;
char S[300005];
int Who[2][300005], Ind[300005], ans;
int Alone[300005];
int TT[300005], Sz[300005], Rev[300005], R[300005];
int Father(int x) {
  int init = x;
  while (x != TT[x]) x = TT[x];
  while (init != x) {
    int next = TT[init];
    TT[init] = x;
    init = next;
  }
  return x;
}
void Unite(int x, int y) {
  if (x == 0 || y == 0 || x == y) return;
  if (R[x] < R[y]) swap(x, y);
  TT[y] = x;
  Alone[x] = max(Alone[x], Alone[y]);
  Sz[x] += Sz[y];
  Rev[x] = Rev[x] == 0 ? Rev[y] : Rev[x];
  Unite(Father(Rev[x]), Father(Rev[y]));
  if (R[x] == R[y]) ++R[x];
}
int getMin(int x) {
  int rev = Father(Rev[x]);
  if (Alone[x] == 1 || Alone[rev] == 2) return Sz[x];
  if (Alone[x] == 2 || Alone[rev] == 1) return Sz[Father(Rev[x])];
  if (Rev[x] == 0) return 0;
  return min(Sz[x], Sz[Father(Rev[x])]);
}
void add0(int x, int y) {
  int f1 = Father(x), f2 = Father(y);
  if (Father(Rev[f1]) == f2) return;
  int nb = getMin(f1) + getMin(f2);
  if (Rev[f1] == 0) Rev[f1] = f2;
  if (Rev[f2] == 0) Rev[f2] = f1;
  Unite(Father(Rev[f1]), f2);
  f2 = Father(f2);
  f1 = Father(f1);
  Unite(Father(Rev[f2]), f1);
  ans -= nb;
  ans += getMin(Father(x));
}
void add1(int x, int y) {
  int f1 = Father(x), f2 = Father(y);
  if (f1 == f2) return;
  int nb = getMin(f1) + getMin(f2);
  Unite(f1, f2);
  Unite(Father(Rev[Father(f1)]), Father(Rev[Father(f2)]));
  ans -= nb;
  ans += getMin(Father(x));
}
void addAlone(int x, int val) {
  int f = Father(x);
  ans -= getMin(f);
  Alone[f] = val;
  ans += getMin(f);
}
void Read() {
  scanf("%d%d", &N, &K);
  scanf("%s", S + 1);
  for (int i = 1; i <= K; i++) {
    TT[i] = i;
    Sz[i] = 1;
    int c;
    scanf("%d", &c);
    for (int j = 1; j <= c; j++) {
      int x;
      scanf("%d", &x);
      Who[Ind[x]++][x] = i;
    }
  }
}
void Solve() {
  for (int i = 1; i <= N; i++) {
    if (Ind[i] == 0) {
      printf("%d\n", ans);
      continue;
    }
    if (Ind[i] == 1)
      addAlone(Who[0][i], S[i] - '0' + 1);
    else {
      if (S[i] == '0')
        add0(Who[0][i], Who[1][i]);
      else
        add1(Who[0][i], Who[1][i]);
    }
    printf("%d\n", ans);
  }
}
int main() {
  Read();
  Solve();
  return 0;
}
