#include <bits/stdc++.h>
using namespace std;
long long shin[25];
long long seto(void);
void ayano(long long x, char spliter = '\n');
int m;
int tans = 0;
vector<int> sts[300005];
vector<int> rs[300005];
int chosen[300005];
int cgst[300005], cgstop = 0;
int visited[300005];
int arr[300005], cnt[300005];
char tstr[300005];
int trych(int x);
void undos(int tp);
void chsing(int x);
int main(void) {
  int n, k;
  n = seto(), k = seto();
  scanf("%s", tstr + 1);
  for (int i = 1; i <= n; i++) arr[i] = (tstr[i] == '0');
  for (int i = 1; i <= k; i++) {
    int t = seto();
    sts[i].reserve(t);
    while (t--) {
      int x = seto();
      cnt[x]++;
      rs[x].push_back(i);
      sts[i].push_back(x);
    }
    sort(sts[i].begin(), sts[i].end());
  }
  for (int i = 1; i <= n; i++) {
    m = i;
    if ((!arr[i])) {
      ayano(tans);
      continue;
    }
    int ians = k + 1;
    int bsti = 0;
    for (auto it = rs[i].begin(); it != rs[i].end(); it++) {
      int u = *it;
      cgstop = 0;
      int ures = trych(u);
      int uans = tans;
      undos(1);
      if (ures && uans < ians) ians = uans, bsti = u;
    }
    cgstop = 0, trych(bsti), undos(0);
    ayano(tans);
  }
  return 0;
}
int trych(int x) {
  chsing(x);
  cgst[cgstop++] = x;
  visited[x] = 1;
  for (auto it = sts[x].begin(); it != sts[x].end(); it++) {
    int v = *it;
    if (v > m) break;
    if (!arr[v]) continue;
    if (cnt[v] == 1) return 0;
    int cgs = 0;
    for (auto itt = rs[v].begin(); itt != rs[v].end(); itt++) {
      int u = *itt;
      if (visited[u] || sts[u][0] < v) continue;
      cgs += trych(u);
    }
    if (!cgs) return 0;
  }
  return 1;
}
void undos(int tp) {
  if (tp) {
    while (cgstop--) visited[cgst[cgstop]] = 0, chsing(cgst[cgstop]);
  } else {
    while (cgstop--) visited[cgst[cgstop]] = 0;
  }
  cgstop = 0;
}
void chsing(int x) {
  if (chosen[x])
    tans--, chosen[x] = 0;
  else
    tans++, chosen[x] = 1;
  for (auto it = sts[x].begin(); it != sts[x].end(); it++) {
    int v = *it;
    arr[v] ^= 1;
  }
}
long long seto(void) {
  long long seto_x = 0;
  int symbol = 0;
  char ch = getchar();
  while (!isdigit(ch)) (ch == '-') ? (symbol = 1) : (0), ch = getchar();
  while (isdigit(ch)) (seto_x = seto_x * 10 + (ch - '0')), ch = getchar();
  return (symbol) ? (-seto_x) : (seto_x);
}
void ayano(long long ayano_x, char spliter) {
  if (!ayano_x) {
    putchar('0'), putchar(spliter);
    return;
  }
  if (ayano_x < 0) putchar('-'), ayano_x = -ayano_x;
  int ayano_len = 0;
  while (ayano_x) {
    long long ayano_d = ayano_x / 10;
    shin[ayano_len++] = ayano_x - ayano_d * 10;
    ayano_x = ayano_d;
  }
  while (ayano_len--) putchar(shin[ayano_len] + '0');
  putchar(spliter);
}
