#include <bits/stdc++.h>
using namespace std;
int ans = 0;
vector<int> edge[300005];
int par[600005], sz[600005];
int k;
int find(int x) { return (par[x] == x) ? x : par[x] = find(par[x]); }
void merge(int x, int y, bool same) {
  int xx = k + x + 1, yy = k + y + 1;
  xx = find(xx), yy = find(yy);
  x = find(x), y = find(y);
  if (same == 1) {
    if (x == y) return;
    ans -= min(sz[x], sz[xx]);
    ans -= min(sz[y], sz[yy]);
    par[x] = y;
    sz[y] += sz[x];
    par[xx] = yy;
    sz[yy] += sz[xx];
  } else {
    if (x == yy) return;
    ans -= min(sz[x], sz[xx]);
    ans -= min(sz[y], sz[yy]);
    par[x] = yy;
    sz[yy] += sz[x];
    par[xx] = y;
    sz[y] += sz[xx];
  }
  ans += min(sz[y], sz[yy]);
  return;
}
int main() {
  int n;
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < k; i++) {
    int c;
    cin >> c;
    while (c--) {
      int x;
      cin >> x;
      --x;
      edge[x].push_back(i);
    }
  }
  for (int i = 0; i < 2 * k + 2; i++) par[i] = i;
  for (int i = 0; i < k; i++) sz[i] = 1, sz[k + i + 1] = 0;
  sz[k] = 0, sz[2 * k + 1] = 10000000;
  for (int i = 0; i < n; i++) {
    if (edge[i].size() == 1) merge(edge[i][0], k, s[i] == '0');
    if (edge[i].size() == 2) merge(edge[i][0], edge[i][1], s[i] == '1');
    cout << ans << endl;
  }
}
