#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int INF = 1e9 + 7;
struct node {
  int l, r;
  node(int _l = 0, int _r = 0) : l(_l), r(_r){};
  void operator+=(node x) {
    l = min(l + x.l, INF);
    r = min(r + x.r, INF);
  }
};
node val[N];
pair<int, int> root[N];
void build(int n = 0) {
  for (int i = 1; i <= n; i++) val[i] = node(1, 0), root[i] = make_pair(i, 0);
}
pair<int, int> getRoot(pair<int, int> u) {
  while (u.first != root[u.first].first) {
    u.second ^= root[u.first].second;
    u.first = root[u.first].first;
  }
  return u;
}
void join(int x, int y, bool s) {
  pair<int, int> u = getRoot(make_pair(x, 0));
  pair<int, int> v = getRoot(make_pair(y, s));
  if (u.first == v.first) return;
  if (u.first > v.first) swap(u, v);
  if (u.second ^ v.second) swap(val[v.first].l, val[v.first].r);
  root[v.first] = make_pair(u.first, u.second ^ v.second);
  val[u.first] += val[v.first];
  val[v.first] = node(0, 0);
}
int get(int u) {
  pair<int, int> tmp = getRoot(make_pair(u, 0));
  return min(val[tmp.first].l, val[tmp.first].r);
}
int update(int x, bool s) {
  pair<int, int> u = getRoot(make_pair(x, s ^ 1));
  if (u.second == 0)
    val[u.first].l = INF;
  else
    val[u.first].r = INF;
}
int n, k;
vector<int> adj[N];
string s;
int main() {
  cin >> n >> k;
  cin >> s;
  for (int i = 1; i <= k; i++) {
    int si;
    cin >> si;
    for (int j = 1; j <= si; j++) {
      int x;
      cin >> x;
      adj[x].push_back(i);
    }
  }
  int curAns = 0;
  build(n);
  for (int i = 1; i <= n; i++) {
    if (adj[i].size() == 1) {
      curAns -= get(adj[i][0]);
      update(adj[i][0], (s[i - 1] == '1'));
      curAns += get(adj[i][0]);
    }
    if (adj[i].size() == 2) {
      pair<int, int> u = getRoot(make_pair(adj[i][0], 0));
      pair<int, int> v = getRoot(make_pair(adj[i][1], 0));
      if (u.first != v.first) {
        curAns -= get(u.first);
        curAns -= get(v.first);
        join(adj[i][0], adj[i][1], (s[i - 1] == '0'));
        curAns += get(adj[i][0]);
      }
    }
    cout << curAns << endl;
  }
}
