#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long nm = 0;
  bool fh = true;
  char cw = getchar();
  for (; !isdigit(cw); cw = getchar()) fh ^= (cw == '-');
  for (; isdigit(cw); cw = getchar()) nm = nm * 10 + (cw - '0');
  return fh ? nm : -nm;
}
char ch[1202000];
int n, m, f[1202000], hv[1202000], t[1202000][2], sz[1202000], ans = 0;
inline int fd(int x) { return x == f[x] ? x : f[x] = fd(f[x]); }
inline int ot(int x) { return (x > m) ? (x - m) : (x + m); }
inline void merge(int a, int b) {
  a = fd(a), b = fd(b);
  if (a == b) return;
  int ota = fd(ot(a)), otb = fd(ot(b));
  ans -= min(hv[a], hv[ota]);
  ans -= min(hv[b], hv[otb]);
  f[a] = b, hv[b] += hv[a], hv[b] = min(hv[b], 1202000 + 1202000);
  f[ota] = otb, hv[otb] += hv[ota], hv[otb] = min(hv[otb], 1202000 + 1202000);
  ans += min(hv[b], hv[otb]);
}
inline void calc(int x) {
  if (!sz[x]) return;
  int a0 = fd(t[x][0]), a1 = fd(t[x][0] + m);
  int b0 = fd(t[x][1]), b1 = fd(t[x][1] + m);
  if (ch[x] == '1') swap(b0, b1);
  merge(a0, b1);
}
inline void solve() {
  n = read(), m = read() + n, scanf("%s", ch + 1);
  for (int i = 1; i <= m + m; i++) f[i] = i, hv[i] = (i > m);
  for (int i = 1; i <= n; i++) hv[m + m - n + i] = 1202000 + 1202000;
  for (int i = 1; i <= n; i++) t[i][0] = t[i][1] = m - n + i;
  for (int i = 1; i <= m - n; i++)
    for (int tt = read(), x; tt; tt--) x = read(), t[x][sz[x]++] = i;
  for (int i = 1; i <= n; i++) calc(i), printf("%d\n", ans);
}
int main() {
  for (int Cas = 1; Cas; --Cas) solve();
  return 0;
}
