#include <bits/stdc++.h>
using namespace std;
string second;
int ans = 0, col[300003][2] = {0}, sz[600006][2] = {0}, p[600006];
int find_set(int i) { return (p[i] == i) ? i : (p[i] = find_set(p[i])); }
void union_set(int i, int j) {
  i = find_set(i), j = find_set(j);
  if (i == j) return;
  ans -= min(sz[i][0], sz[i][1]) + min(sz[j][0], sz[j][1]);
  p[j] = i;
  sz[i][0] += sz[j][0], sz[i][1] += sz[j][1];
  ans += min(sz[i][0], sz[i][1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k >> second;
  for (int i = 0; i < k; ++i) {
    int c;
    cin >> c;
    while (c--) {
      int x;
      cin >> x;
      if (col[x][0])
        col[x][1] = i + 1;
      else
        col[x][0] = i + 1;
    }
  }
  for (int i = 0; i < 2 * (k + 1); ++i) {
    p[i] = i;
    sz[i][i > k] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    if (second[i - 1] == '1') {
      union_set(col[i][0], col[i][1]);
      union_set(col[i][0] + k + 1, col[i][1] + k + 1);
    } else {
      union_set(col[i][0], col[i][1] + k + 1);
      union_set(col[i][0] + k + 1, col[i][1]);
    }
    int x = find_set(0);
    if (sz[x][0] < sz[x][1])
      cout << ans / 2 - sz[x][0] + sz[x][1] << '\n';
    else
      cout << ans / 2 << '\n';
  }
}
