#include <bits/stdc++.h>
using namespace std;
template <typename elemType>
inline void Read(elemType &T) {
  elemType X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  T = (w ? -X : X);
}
vector<int> G[300010];
char Str[300010];
int S[600010], Rank[600010], Value[600010];
int N, K, Ans = 0;
int Find(int u) {
  if (S[u] == 0) return u;
  return S[u] = Find(S[u]);
}
void union_set(int u, int v) {
  if ((u = Find(u)) == (v = Find(v)))
    return;
  else if (Rank[u] > Rank[v]) {
    S[v] = u;
    Value[u] += Value[v];
  } else if (Rank[u] < Rank[v]) {
    S[u] = v;
    Value[v] += Value[u];
  } else {
    S[v] = u;
    Rank[u]++;
    Value[u] += Value[v];
  }
}
inline int Val(int u) { return min(Value[Find(u)], Value[Find(u + K)]); }
int main() {
  Read(N);
  Read(K);
  scanf("%s", Str + 1);
  for (register int i = 1; i <= K; ++i) {
    Value[i + K] = 1;
    int Len;
    Read(Len);
    for (register int j = 1; j <= Len; ++j) {
      int x;
      Read(x);
      G[x].push_back(i);
    }
  }
  Value[K * 2 + 1] = 0x3f3f3f3f;
  for (register int i = 1; i <= N; ++i) {
    if (G[i].size() == 1) {
      int u = G[i][0];
      if (Str[i] == '1') u += K;
      Ans -= Val(G[i][0]);
      union_set(u, K * 2 + 1);
      Ans += Val(G[i][0]);
    } else if (G[i].size() == 2) {
      int u = G[i][0], v = G[i][1];
      if (Str[i] == '0' && Find(u) != Find(v + K)) {
        Ans -= Val(u) + Val(v);
        union_set(u, v + K);
        union_set(u + K, v);
        Ans += Val(u);
      } else if (Str[i] == '1' && Find(u) != Find(v)) {
        Ans -= Val(u) + Val(v);
        union_set(u, v);
        union_set(u + K, v + K);
        Ans += Val(u);
      }
    }
    printf("%d\n", Ans);
  }
  return 0;
}
