#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;
stringstream sss;
const long long int maxn = 300010;
long long int n, k;
string second;
long long int init[maxn];
long long int rt[maxn * 2];
vector<long long int> adj[maxn];
long long int ans = 0;
const long long int ON = maxn * 2 - 2;
const long long int OFF = maxn * 2 - 1;
long long int root(long long int x) {
  return x == rt[x] ? x : rt[x] = root(rt[x]);
}
struct Part {
  long long int sz = 0;
  long long int other;
  vector<long long int> ver;
  void add(long long int x) {
    ++sz;
    ver.emplace_back(x);
  }
  void insert(Part &x) {
    sz += x.sz;
    for (auto y : x.ver) ver.emplace_back(y);
  }
} ar[maxn * 2];
long long int cost(long long int x) {
  return min(ar[x].sz, ar[ar[x].other].sz);
}
void merge_biparts(long long int a, long long int b) {
  long long int ra = root(a), rb = root(b);
  if (ra == rb) return;
  ans -= cost(ra) + cost(rb);
  if (ar[ra].sz < ar[rb].sz) swap(ra, rb);
  ar[ra].insert(ar[rb]);
  long long int rc = root(ar[ra].other), rd = root(ar[rb].other);
  if (ar[rc].sz < ar[rd].sz) swap(rc, rd);
  ar[rc].insert(ar[rd]);
  ar[rc].other = ra, ar[ra].other = rc;
  rt[rd] = rc;
  rt[rb] = ra;
  ans += cost(ra);
}
void MAIN() {
  cin >> n >> k >> second;
  for (long long int i = (0); i < (n); ++i) init[i] = second[i] == '1';
  for (long long int i = (0); i < (k); ++i) {
    long long int a;
    cin >> a;
    for (long long int j = (0); j < (a); ++j) {
      long long int x;
      cin >> x;
      --x;
      adj[x].emplace_back(i);
    }
  }
  iota(rt, rt + maxn * 2, 0);
  for (long long int i = (0); i < (k); ++i)
    ar[i].other = i + k, ar[i + k].other = i, ar[i].add(i);
  ar[OFF].sz = BIG, ar[OFF].other = ON, ar[ON].other = OFF;
  for (long long int i = (0); i < (n); ++i) {
    if (adj[i].empty()) {
      cout << ans << '\n';
      continue;
    }
    if (adj[i].size() == 1) {
      adj[i].emplace_back(OFF);
    }
    long long int a = adj[i][0];
    long long int b = adj[i][1];
    if (init[i]) {
      merge_biparts(a, b);
    } else {
      merge_biparts(a, ar[root(b)].other);
    }
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(10);
  sss << R"(
3 0
111
2
1 2
2
1 3
7 3
0011100
3
1 4 6
3
3 4 7
2
2 3
    )";
  MAIN();
  return 0;
}
