#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
const long long inf64 = 1e18;
int ans = 0;
vector<int> p, st, pr, sz;
int get(int v) { return (p[v] == v ? v : p[v] = get(p[v])); }
int gsz(int v) { return (v == -1 ? 0 : sz[v]); }
int get_opt(pair<int, int> a) {
  if (a.first != -1 && st[a.first] != -1) {
    if (st[a.first]) {
      return gsz(a.first);
    } else {
      return gsz(a.second);
    }
  }
  if (a.second != -1 && st[a.second] != -1) {
    if (st[a.second]) {
      return gsz(a.second);
    } else {
      return gsz(a.first);
    }
  }
  return min(gsz(a.first), gsz(a.second));
}
void make_strict(int i, int val) {
  i = get(i);
  int o = pr[i];
  ans -= get_opt({i, o});
  st[i] = val;
  ans += get_opt({i, o});
}
pair<int, int> merge_p(pair<int, int> a, pair<int, int> b) {
  int l = (gsz(a.first) < gsz(b.first) ? b.first : a.first);
  int r = (gsz(a.second) < gsz(b.second) ? b.second : a.second);
  if (r != -1) {
    pr[r] = l;
    if (r == a.second && b.second != -1 && b.second != r) {
      sz[r] += gsz(b.second);
      p[b.second] = r;
      if (st[b.second] != -1) st[r] = st[b.second];
    }
    if (r == b.second && a.second != -1 && a.second != r) {
      sz[r] += gsz(a.second);
      p[a.second] = r;
      if (st[a.second] != -1) st[r] = st[a.second];
    }
  }
  if (l != -1) {
    pr[l] = r;
    if (l == a.first && b.first != -1 && b.first != l) {
      sz[l] += gsz(b.first);
      p[b.first] = l;
      if (st[b.first] != -1) st[l] = st[b.first];
    }
    if (l == b.first && a.first != -1 && a.first != l) {
      sz[l] += gsz(a.first);
      p[a.first] = l;
      if (st[a.first] != -1) st[l] = st[a.first];
    }
  }
  return {l, r};
}
void merge(int a, int b, int val) {
  a = get(a);
  b = get(b);
  pair<int, int> fr = {a, pr[a]};
  pair<int, int> sc = {b, pr[b]};
  if (val) {
    swap(sc.first, sc.second);
  }
  if (fr.first != sc.first && fr.first != -1) {
    ans -= get_opt(sc);
    ans -= get_opt(fr);
    pair<int, int> nw = merge_p(fr, sc);
    ans += get_opt(nw);
  }
}
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> cur(n);
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    cur[i] = c - '0';
  }
  vector<vector<int>> w(n);
  for (int i = 0; i < k; i++) {
    int c;
    cin >> c;
    while (c--) {
      int x;
      cin >> x;
      x--;
      w[x].push_back(i);
    }
  }
  p.resize(k);
  iota(p.begin(), p.end(), 0);
  pr.resize(k, -1);
  st.resize(k, -1);
  sz.resize(k, 1);
  for (int i = 0; i < n; i++) {
    if (w[i].size() == 0) {
      cout << ans << '\n';
      continue;
    }
    if (w[i].size() == 1) {
      make_strict(w[i][0], cur[i] ^ 1);
      cout << ans << '\n';
      continue;
    }
    int a = w[i][0], b = w[i][1];
    merge(a, b, cur[i] ^ 1);
    cout << ans << '\n';
  }
  return 0;
}
