#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int uni[N], perm[N];
vector<pair<int, int>> adj[N];
std::vector<int> g[N];
int n, k;
string s;
int col[N];
int curAns;
struct node {
  bool flag, perm;
  std::vector<int> elems;
  int cnt[2];
  node() {
    flag = false;
    perm = false;
    memset(cnt, 0, sizeof cnt);
    cnt[0] = 1;
  }
};
std::vector<node> nodes;
int uni_find(int x) { return uni[x] = (uni[x] == x ? x : uni_find(uni[x])); }
int answer(int x) {
  if (!nodes[x].perm) return min(nodes[x].cnt[0], nodes[x].cnt[1]);
  return nodes[x].cnt[nodes[x].flag ^ 1];
}
void unio(int x, int y, int c) {
  int a = uni_find(x), b = uni_find(y);
  if (a == b) return;
  if (nodes[a].elems.size() < nodes[b].elems.size()) swap(a, b);
  curAns -= answer(a);
  curAns -= answer(b);
  if (c == 1) {
    if (nodes[b].perm) {
      nodes[a].flag ^= 1;
    } else
      nodes[b].flag ^= 1;
  }
  for (auto x : nodes[b].elems) {
    col[x] ^= nodes[b].flag;
    col[x] ^= nodes[a].flag;
    nodes[a].cnt[col[x]]++;
    nodes[a].elems.push_back(x);
  }
  nodes[a].perm |= nodes[b].perm;
  uni[b] = a;
  nodes[b].elems.clear();
  curAns += answer(a);
}
int getColor(int x) {
  int p = uni_find(x);
  if (nodes[p].flag) return col[x] ^ 1;
  return col[x];
}
void flip(int node) {
  node = uni_find(node);
  curAns -= min(nodes[node].cnt[0], nodes[node].cnt[1]);
  nodes[node].flag ^= 1;
  curAns += nodes[node].cnt[nodes[node].flag ^ 1];
}
int main() {
  scanf("%d %d", &n, &k);
  cin >> s;
  for (int j = 0; j < k; j++) {
    int sz;
    cin >> sz;
    for (int i = 0, x; i < sz; i++) {
      cin >> x;
      g[x - 1].push_back(j);
    }
  }
  for (int i = 0; i < k; i++) {
    nodes.push_back(node());
    nodes.back().elems.push_back(i);
    uni[i] = i;
  }
  for (int i = 0; i < n; i++) {
    if (g[i].empty()) {
      cout << curAns << '\n';
      continue;
    }
    if (g[i].size() == 1) {
      int node = g[i][0];
      int newColor = (s[i] - '0') ^ 1;
      if (getColor(node) == newColor) {
        curAns -= answer(uni_find(node));
        nodes[uni_find(node)].perm = 1;
        curAns += answer(uni_find(node));
      } else {
        flip(node);
      }
      nodes[uni_find(node)].perm = 1;
      cout << curAns << '\n';
    } else {
      int u = g[i][0];
      int v = g[i][1];
      int relation = (s[i] - '0') ^ 1;
      if (!relation) {
        if (getColor(u) == getColor(v)) {
          unio(u, v, 0);
        } else {
          unio(u, v, 1);
        }
      } else {
        if (getColor(u) != getColor(v)) {
          unio(u, v, 0);
        } else {
          unio(u, v, 1);
        }
      }
      cout << curAns << '\n';
    }
  }
  return 0;
}
