#include <bits/stdc++.h>
using namespace std;
long long n, m, k, a, b, c, d, e, q, ans;
long long ata[2 * 300005], ataans[2 * 300005], atas[2 * 300005],
    flag[2 * 300005];
char s[300005];
vector<long long> v[300005];
long long atabul(long long a) { return ata[a] == a ? a : atabul(ata[a]); }
void birlestir(long long a, long long b) {
  a = atabul(a);
  b = atabul(b);
  if (a == b) return;
  if (atas[a] < atas[b]) {
    ata[a] = b;
    atas[b] += atas[a];
    ataans[b] += ataans[a];
    flag[b] |= flag[a];
  } else {
    ata[b] = a;
    atas[a] += atas[b];
    ataans[a] += ataans[b];
    flag[a] |= flag[b];
  }
}
bool pr = false;
void hesap(long long a, long long b, long long sa) {
  a = atabul(a);
  b = atabul(b);
  if (a == b) return;
  if (pr)
    cerr << a << " " << b << " $ " << ataans[a] << " " << flag[a] << " / "
         << ataans[b] << " " << flag[b] << "\n";
  if (flag[a]) {
    ans += sa * ataans[a];
  } else if (flag[b]) {
    ans += sa * ataans[b];
  } else {
    ans += sa * min(ataans[a], ataans[b]);
  }
}
void update(long long i) {
  if (s[i] == '1') {
    if (v[i].size() == 1) {
      c = v[i][0];
      e = atabul(c + k);
      d = atabul(c);
      if (!flag[e]) {
        ans -= min(ataans[e], ataans[d]);
        flag[e] = 1;
        ans += ataans[e];
      }
    } else if (v[i].size() == 2) {
      b = v[i][0];
      c = v[i][1];
      if (atabul(b) != atabul(c)) {
        hesap(b, b + k, -1);
        hesap(c, c + k, -1);
        birlestir(b, c);
        birlestir(b + k, c + k);
        hesap(b, b + k, 1);
      }
    }
  } else {
    if (v[i].size() == 1) {
      c = v[i][0];
      e = atabul(c + k);
      d = atabul(c);
      if (!flag[d]) {
        ans -= min(ataans[e], ataans[d]);
        flag[d] = 1;
        ans += ataans[d];
      }
    } else if (v[i].size() == 2) {
      b = v[i][0];
      c = v[i][1];
      if (atabul(b) != atabul(c + k)) {
        if (i == 5) {
        } else {
          pr = false;
        }
        hesap(b, b + k, -1);
        hesap(c, c + k, -1);
        birlestir(b, c + k);
        birlestir(b + k, c);
        hesap(b, b + k, 1);
      }
    }
  }
}
int32_t main() {
  cin >> n >> k;
  scanf("%s", s + 1);
  for (long long i = 1; i <= k; i++) {
    scanf("%lld", &a);
    for (long long j = 0; j < a; j++) {
      scanf("%lld", &b);
      v[b].push_back(i);
    }
  }
  for (long long i = 0; i <= k; i++) {
    ata[i] = i;
    atas[i] = 1;
    ataans[i] = 1;
    flag[i] = 0;
  }
  for (long long i = k + 1; i <= (k + k); i++) {
    ata[i] = i;
    atas[i] = 1;
    ataans[i] = 0;
    flag[i] = 0;
  }
  for (long long i = 1; i <= n; i++) {
    update(i);
    printf("%lld\n", ans);
  }
}
