#include <bits/stdc++.h>
template <typename T>
bool ckmax(T &x, T y) {
  return x < y ? x = y, true : false;
}
template <typename T>
bool ckmin(T &x, T y) {
  return x > y ? x = y, true : false;
}
using namespace std;
const long long inf = 1000000000;
const double Pi = acos(-1);
const int mod = 1e9 + 7;
const double eps = 1e-6;
inline int fpow(int a, int b = mod - 2, int p = mod) {
  a %= p;
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % p;
    a = 1ll * a * a % p;
    b >>= 1;
  }
  return res;
}
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    write(-x);
    return;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) {
  write(x);
  putchar('\n');
}
int n, m;
char str[333333];
int l[333333], r[333333];
int siz[333333], tag[333333], fa[333333];
int val[333333], opt[333333];
int ans;
inline pair<int, int> fdf(int x) {
  int t = tag[x];
  while (fa[x]) x = fa[x], t ^= tag[x];
  return make_pair(x, t);
}
inline void mrg(int x, int y) {
  fa[x] = y;
  siz[y] += siz[x];
  val[y] += val[x];
  opt[y] |= opt[x];
  tag[x] ^= tag[y];
}
signed main() {
  n = read(), m = read(), scanf("%s", str + 1);
  for (int i = (1), iE = (m); i <= iE; i++) {
    siz[i] = 1;
    static int t, x;
    t = read();
    for (int j = (1), jE = (t); j <= jE; j++) {
      x = read();
      if (l[x])
        r[x] = i;
      else
        l[x] = i;
    }
  }
  for (int i = (1), iE = (n); i <= iE; i++) {
    if (!r[i]) {
      if (!l[i]) {
        writeln(ans);
        continue;
      }
      pair<int, int> t = fdf(l[i]);
      if (t.second == (str[i] - '0'))
        tag[t.first] ^= 1, ans += (siz[t.first] - 2 * val[t.first]),
            val[t.first] = siz[t.first] - val[t.first];
      opt[t.first] = 1;
      writeln(ans);
      continue;
    }
    pair<int, int> t = fdf(l[i]), tt = fdf(r[i]);
    if (t.first == tt.first) {
      writeln(ans);
      continue;
    }
    if (siz[t.first] > siz[tt.first]) swap(t, tt);
    int ct = 0;
    ct += t.second, ct += tt.second, ct += (str[i] == '1');
    if (ct % 2 == 0) {
      int ta = siz[t.first] - 2 * val[t.first],
          tb = siz[tt.first] - 2 * val[tt.first];
      if ((ta < tb && !opt[t.first]) || opt[tt.first]) {
        ans += ta;
        val[t.first] = siz[t.first] - val[t.first];
        tag[t.first] ^= 1;
      } else {
        ans += tb;
        val[tt.first] = siz[tt.first] - val[tt.first];
        tag[tt.first] ^= 1;
      }
    }
    mrg(t.first, tt.first);
    writeln(ans);
  }
}
