#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 20;
vector<int> bad[N], comp[N];
int off[N], delta[N], col[N];
long long cnt_on[N];
long long ans = 0;
bool hatman[N];
long long ok(long long x) {
  x += 10;
  x %= 2;
  return x;
}
inline void mer(int u, int v, int f) {
  int c1 = col[v], c2 = col[u];
  if (c1 == c2) return;
  if ((int)comp[c1].size() > (int)comp[c2].size()) swap(c1, c2);
  long long avaz = 0;
  if (ok(off[u] + off[v] + delta[c1] + delta[c2]) != ok(f)) {
    long long d1 = ((int)comp[c1].size() - cnt_on[c1]) - cnt_on[c1];
    long long d2 = ((int)comp[c2].size() - cnt_on[c2]) - cnt_on[c2];
    avaz = 1;
    if (hatman[c1] || (d2 <= d1 && !hatman[c2])) {
      cnt_on[c2] = (int)comp[c2].size() - cnt_on[c2] + cnt_on[c1];
      delta[c2] = ok(delta[c2] + 1);
      ans += d2;
      avaz = 0;
    } else {
      ans += d1;
      cnt_on[c2] = cnt_on[c2] + (int)comp[c1].size() - cnt_on[c1];
      avaz = 1;
    }
  } else
    cnt_on[c2] += cnt_on[c1];
  for (auto x : comp[c1]) {
    comp[c2].push_back(x);
    col[x] = c2;
    off[x] = ok(off[x] + delta[c1]);
    if (avaz) off[x] = ok(off[x] + 1);
    if (delta[c2]) off[x] = ok(off[x] + 1);
  }
  hatman[c2] = hatman[c2] || hatman[c1];
  vector<int>().swap(comp[c1]);
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) s[i] = char(1 - (s[i] - '0') + '0');
  for (int i = 0; i < k; i++) {
    int tt;
    cin >> tt;
    for (int j = 0; j < tt; j++) {
      int x;
      cin >> x;
      x--;
      bad[x].push_back(i);
    }
  }
  for (int i = 0; i < k; i++) {
    comp[i].push_back(i);
    col[i] = i;
    cnt_on[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    if ((int)bad[i].size() == 0) {
      cout << ans << '\n';
      continue;
    }
    if ((int)bad[i].size() == 1) {
      int u = bad[i].back();
      hatman[col[u]] = true;
      int x = s[i] - '0';
      if (ok(off[u] + delta[col[u]]) == ok(x)) {
        cout << ans << '\n';
        continue;
      }
      u = col[u];
      delta[u] = ok(delta[u] + 1);
      ans -= cnt_on[u];
      cnt_on[u] = (int)comp[u].size() - cnt_on[u];
      ans += cnt_on[u];
      cout << ans << '\n';
      continue;
    }
    int x = s[i] - '0';
    int u = bad[i][0], v = bad[i].back();
    mer(u, v, x);
    cout << ans << '\n';
  }
  return 0;
}
