#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long maxn = 300005;
const long long inf = 1ll << 50;
int ans = 0;
bool init[maxn];
int par[maxn], sz[maxn], cnt[maxn][2], col[maxn];
vector<int> vec[maxn];
int find(int x) {
  if (par[x] == x) {
    return x;
  }
  int tmp = find(par[x]);
  col[x] = col[x] ^ col[par[x]];
  return par[x] = tmp;
}
int get_val(int x) { return min(cnt[x][0], cnt[x][1]); }
void merge(int X, int Y, bool same) {
  int x = find(X);
  int y = find(Y);
  if (x == y) {
    return;
  }
  if (sz[x] > sz[y]) {
    swap(x, y);
  }
  sz[y] += sz[x];
  par[x] = y;
  same = (same ^ col[X] ^ col[Y]);
  ans -= get_val(x);
  ans -= get_val(y);
  col[x] = same;
  cnt[y][0] += cnt[x][0 ^ same];
  cnt[y][1] += cnt[x][1 ^ same];
  ans += get_val(y);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  sz[0] = (1 << 28);
  cnt[0][0] = (1 << 28);
  for (int i = 1; i <= k; i++) {
    par[i] = i;
    sz[i] += 1;
    cnt[i][0] = 1;
    cnt[i][1] = 0;
  }
  string s;
  cin >> s;
  for (int i = 1; i <= n; i++) {
    init[i] = s[i - 1] - '0';
  }
  for (int i = 1; i <= k; i++) {
    long long c;
    cin >> c;
    int a;
    for (int j = 0; j < c; j++) {
      cin >> a;
      vec[a].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    assert(vec[i].size() <= 2);
    if (vec[i].size() == 0) {
      cout << ans << "\n";
      assert(init[i] == 1);
      continue;
    }
    if (vec[i].size() == 1) {
      vec[i].push_back(0);
    }
    merge(vec[i][0], vec[i][1], init[i] ^ 1);
    cout << ans << "\n";
  }
  return 0;
}
