#include <bits/stdc++.h>
const int mod = 1000000007;
const int inf = 1000000009;
const long long INF = 1000000000000000009;
const long long big = 1000000000000000;
const long double eps = 0.000000000000000000001;
using namespace std;
vector<pair<int, int> > P[300005];
vector<int> L[300005];
int K[300005], R[300005], U[300005], A[300005], B[300005];
bool O[300005];
int wynik = 0;
void dfs(int n, int k) {
  K[n] = k;
  O[n] = 1;
  for (auto v : P[n]) {
    if (!O[v.first]) dfs(v.first, (k + v.second) % 2);
  }
}
int Find(int x) {
  if (x == R[x]) return x;
  return R[x] = Find(R[x]);
}
void Union(int a, int b, int c) {
  int x = Find(a);
  int y = Find(b);
  if (x == y) return;
  if (U[y]) swap(x, y);
  int d;
  if (U[x] == 1)
    d = A[x];
  else if (U[x] == -1)
    d = B[x];
  else
    d = min(A[x], B[x]);
  wynik -= d;
  int ok = 0;
  if (K[a] != K[x]) ok++;
  if (K[b] != K[y]) ok++;
  ok += c;
  ok %= 2;
  if (ok == 0)
    A[x] += A[y], B[x] += B[y];
  else
    A[x] += B[y], B[x] += A[y];
  if (U[y] == 1)
    d = A[y];
  else if (U[y] == -1)
    d = B[y];
  else
    d = min(A[y], B[y]);
  wynik -= d;
  if (U[x] == 1)
    wynik += A[x];
  else if (U[x] == -1)
    wynik += B[x];
  else
    wynik += min(A[x], B[x]);
  R[y] = x;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n, k;
  cin >> n >> k;
  string napis;
  cin >> napis;
  napis = '#' + napis;
  for (int i = 1; i <= k; i++) {
    int r;
    cin >> r;
    for (int j = 1; j <= r; j++) {
      int a;
      cin >> a;
      L[a].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    int x = napis[i] - '0';
    x = (x + 1) % 2;
    if (L[i].size() == 2) {
      int a = L[i][0];
      int b = L[i][1];
      P[a].push_back(make_pair(b, x));
      P[b].push_back(make_pair(a, x));
    }
  }
  for (int i = 1; i <= k; i++) {
    if (!O[i]) dfs(i, 1);
  }
  for (int i = 1; i <= k; i++) {
    R[i] = i;
    A[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    int w = napis[i] - '0';
    w = (w + 1) % 2;
    if ((int)L[i].size() == 1) {
      int x = Find(L[i].back());
      if (!U[x]) {
        wynik -= min(A[x], B[x]);
        int t = napis[i] - '0';
        if (K[x] != K[L[i].back()]) t++;
        t %= 2;
        if (t == 0) {
          U[x] = 1;
          wynik += A[x];
        } else {
          U[x] = -1;
          wynik += B[x];
        }
      }
    } else if ((int)L[i].size() == 2) {
      Union(L[i][0], L[i][1], w);
    }
    cout << wynik << "\n";
  }
  return 0;
}
