#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e5 + 10;
int n, k, A[maxn];
string s;
struct DSU {
  int par[maxn], p[maxn], rv[maxn], cnt[maxn][2];
  vector<int> v[maxn];
  int ans = 0;
  DSU() {
    for (int i = 0; i < maxn; i++) {
      v[i].push_back(i);
      rv[i] = -1;
      cnt[i][0] = 1;
      par[i] = i;
    }
  }
  int cal(int a) {
    if (rv[a] == -1) {
      return min(cnt[a][0], cnt[a][1]);
    } else {
      return cnt[a][1 - rv[a]];
    }
  }
  void add(int a, bool c) {
    ans -= cal(par[a]);
    assert(rv[par[a]] == -1 || c == (rv[par[a]] ^ p[a]));
    rv[par[a]] = (c ^ p[a]);
    ans += cal(par[a]);
  }
  void merge(int a, int b, bool c) {
    if (par[a] == par[b]) {
      ans -= cal(par[a]);
      assert(c == (p[a] ^ p[b]));
      ans += cal(par[a]);
      return;
    }
    ans -= cal(par[a]);
    ans -= cal(par[b]);
    c ^= p[a];
    c ^= p[b];
    a = par[a];
    b = par[b];
    if (v[a].size() < v[b].size()) {
      swap(a, b);
    }
    if (rv[a] == -1 && rv[b] != -1) {
      rv[a] = c ^ rv[b];
    }
    if (rv[b] != -1 && rv[b] != -1) {
      assert(rv[a] == c ^ rv[b]);
    }
    cnt[a][0] += cnt[b][c];
    cnt[a][1] += cnt[b][1 - c];
    for (int x : v[b]) {
      v[a].push_back(x);
      p[x] ^= c;
      par[x] = a;
    }
    v[b].clear();
    ans += cal(a);
  }
} dsu;
vector<int> g[maxn];
int main() {
  cin >> n >> k >> s;
  for (int i = 0; i < k; i++) {
    int sz;
    cin >> sz;
    for (int j = 0; j < sz; j++) {
      int a;
      cin >> a;
      a--;
      g[a].push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    assert(g[i].size() > 0 || s[i] == '1');
    assert(g[i].size() < 3);
    if (g[i].size() == 1) {
      dsu.add(g[i][0], s[i] == '0');
    }
    if (g[i].size() == 2) {
      dsu.merge(g[i][0], g[i][1], s[i] == '0');
    }
    cout << dsu.ans << endl;
  }
}
