#include <bits/stdc++.h>
using namespace std;
struct rec {
  int l, r;
} ele[300005];
struct node {
  int to;
  bool same;
  node *next;
} * nd[300005];
int k, i, j, m, n, x, father[300005], nowans;
int colour[300005], cnt_node[300005], cnt_one[300005], ans[300005],
    took[300005];
int must_take[300005], cnt[300005];
char s[300005];
bool visit[300005];
void dfs(int u, int pre) {
  node *p = nd[u];
  visit[u] = true;
  while (p) {
    if (!visit[p->to]) {
      if (p->same)
        colour[p->to] = colour[u];
      else
        colour[p->to] = 3 - colour[u];
      dfs(p->to, u);
    }
    p = p->next;
  }
}
void addd(int u, int v, bool same) {
  node *p = new node();
  p->to = v;
  p->same = same;
  p->next = nd[u];
  nd[u] = p;
}
int getfather(int u) {
  if (father[u] == u) return u;
  father[u] = getfather(father[u]);
  return father[u];
}
int main() {
  scanf("%d%d", &n, &k);
  scanf("%s", s);
  for (i = 1; i <= k; i++) {
    scanf("%d", &cnt[i]);
    for (j = 1; j <= cnt[i]; j++) {
      scanf("%d", &x);
      if (ele[x].l == 0) {
        ele[x].l = i;
      } else {
        ele[x].r = i;
        bool same;
        if (s[x - 1] == '1') {
          same = true;
        } else {
          same = false;
        }
        addd(ele[x].l, ele[x].r, same);
        addd(ele[x].r, ele[x].l, same);
      }
    }
  }
  for (i = 1; i <= k; i++) {
    if (!visit[i]) {
      colour[i] = 1;
      dfs(i, -1);
    }
  }
  for (i = 1; i <= k; i++) {
    father[i] = i;
    cnt_node[i] = 1;
    if (colour[i] == 1) {
      cnt_one[i] = 1;
      took[i] = 2;
      ans[i] = 0;
    } else {
      cnt_one[i] = 0;
      took[i] = 1;
      ans[i] = 0;
    }
  }
  for (i = 1; i <= n; i++) {
    if (ele[i].l == 0) {
      printf("%d\n", nowans);
    } else if (ele[i].r == 0) {
      int u = ele[i].l;
      int fa = getfather(father[u]);
      nowans -= ans[fa];
      if (s[i - 1] == '1') {
        must_take[fa] = 3 - colour[u];
      } else {
        must_take[fa] = colour[u];
      }
      took[fa] = must_take[fa];
      if (must_take[fa] == 1) {
        ans[fa] = cnt_one[fa];
      } else {
        ans[fa] = cnt_node[fa] - cnt_one[fa];
      }
      nowans += ans[fa];
      printf("%d\n", nowans);
    } else {
      int u1 = ele[i].l;
      int u2 = ele[i].r;
      int fa1 = getfather(father[u1]);
      int fa2 = getfather(father[u2]);
      if (fa1 != fa2) {
        if (cnt_node[fa1] < cnt_node[fa2]) {
          int temp = fa1;
          fa1 = fa2;
          fa2 = temp;
        }
        nowans = nowans - ans[fa1] - ans[fa2];
        father[fa2] = fa1;
        cnt_node[fa1] += cnt_node[fa2];
        cnt_one[fa1] += cnt_one[fa2];
        if (must_take[fa2] > 0) must_take[fa1] = must_take[fa2];
        if (must_take[fa1] == 0) {
          if (cnt_one[fa1] < cnt_node[fa1] - cnt_one[fa1]) {
            ans[fa1] = cnt_one[fa1];
            took[fa1] = 1;
          } else {
            ans[fa1] = cnt_node[fa1] - cnt_one[fa1];
            took[fa1] = 2;
          }
        } else if (must_take[fa1] == 1) {
          ans[fa1] = cnt_one[fa1];
          took[fa1] = 1;
        } else {
          ans[fa1] = cnt_node[fa1] - cnt_one[fa1];
          took[fa1] = 2;
        }
        nowans += ans[fa1];
      }
      printf("%d\n", nowans);
    }
  }
  return 0;
}
