#include <bits/stdc++.h>
const int inf = (1ll << 30) - 1;
const int maxn = (int)1e6 + 10;
const int mod = (int)1e9 + 7;
using namespace std;
int n, k;
char c[maxn];
vector<int> g[maxn];
int sz = 1;
long long S[maxn];
int p[maxn];
int pos[maxn];
int neg[maxn];
int ans = 0;
map<pair<int, int>, int> cur;
int C[maxn];
int T[maxn];
void erase(int x, int u) {
  if (cur.find(make_pair(x, u)) != cur.end()) {
    ans -= cur[make_pair(x, u)];
    cur.erase(make_pair(x, u));
  }
}
void add(int x, int u) {
  ans += min(S[x], S[u]);
  cur[make_pair(x, u)] = min(S[x], S[u]);
}
int get(int v) {
  if (p[v] == v) return v;
  return p[v] = get(p[v]);
}
void create(int x) {
  if (pos[x] == 0) {
    pos[x] = sz;
    S[sz] = 1;
    p[sz] = sz;
    T[sz] = 1;
    sz++;
    neg[x] = sz;
    p[sz] = sz;
    T[sz] = 1;
    sz++;
    add(pos[x], neg[x]);
  }
}
void MERGE(int u, int v) {
  int pu = get(u);
  int pv = get(v);
  if (pu == pv) return;
  p[pu] = pv;
  S[pv] += S[pu];
  T[pv] += T[pu];
}
void mergeOp(int u, int v) {
  create(u);
  create(v);
  int pos_u = get(pos[u]);
  int pos_v = get(pos[v]);
  int neg_u = get(neg[u]);
  int neg_v = get(neg[v]);
  erase(pos_u, neg_u);
  erase(pos_v, neg_v);
  erase(neg_u, pos_u);
  erase(neg_v, pos_v);
  MERGE(pos_u, pos_v);
  MERGE(neg_u, neg_v);
  int posv = get(pos[v]);
  int negv = get(neg[v]);
  if (posv == negv) {
  } else {
    add(posv, negv);
  }
}
void merge(int u, int v) {
  create(u);
  create(v);
  int pos_u = get(pos[u]);
  int pos_v = get(pos[v]);
  int neg_u = get(neg[u]);
  int neg_v = get(neg[v]);
  erase(pos_u, neg_u);
  erase(pos_v, neg_v);
  erase(neg_u, pos_u);
  erase(neg_v, pos_v);
  MERGE(pos_u, neg_v);
  MERGE(neg_u, pos_v);
  int posv = get(pos[v]);
  int negv = get(neg[v]);
  if (posv == negv) {
  } else {
    add(posv, negv);
  }
}
void solve() {
  scanf("%d%d", &n, &k);
  scanf("%s", c);
  for (int i = 1; i <= k; i++) {
    int second;
    scanf("%d", &second);
    for (int j = 0; j < second; j++) {
      int x;
      scanf("%d", &x);
      g[x].push_back(i);
    }
  }
  int d = k + 1;
  for (int i = 1; i <= n; i++) {
    if (c[i - 1] == '1') {
      int t = g[i].size();
      if (t == 0) {
      } else if (t == 1) {
        create(d);
        erase(pos[d], neg[d]);
        erase(neg[d], pos[d]);
        S[neg[d]] = 0;
        S[pos[d]] = inf;
        mergeOp(d, g[i][0]);
        d++;
      } else {
        mergeOp(g[i][0], g[i][1]);
      }
    } else {
      int t = g[i].size();
      if (t == 1) {
        create(d);
        erase(pos[d], neg[d]);
        erase(neg[d], pos[d]);
        S[neg[d]] = inf;
        S[pos[d]] = 0;
        mergeOp(d, g[i][0]);
        d++;
      } else {
        merge(g[i][0], g[i][1]);
      }
    }
    cout << ans << "\n";
  }
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
