#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
int n, k, par[maxn], sz[maxn][2], fix[maxn], a[maxn], label[maxn], cost[maxn],
    res;
bool vis[maxn];
vector<pair<int, int> > g[maxn];
vector<int> groups[maxn];
void dfs(int u, int p) {
  vis[u] = true;
  for (pair<int, int> v : g[u]) {
    if (v.first == p || vis[v.first]) continue;
    if (v.second == 0)
      label[v.first] = !label[u];
    else
      label[v.first] = label[u];
    dfs(v.first, u);
  }
}
inline int ro(int n) {
  while (n != par[n]) {
    par[n] = par[par[n]];
    n = par[n];
  }
  return n;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    char c;
    scanf(" %c", &c);
    a[i] = c - '0';
  }
  for (int i = 1; i <= k; i++) {
    int a;
    scanf(" %d", &a);
    while (a--) {
      int v;
      scanf(" %d", &v);
      groups[v].push_back(i);
    }
  }
  memset(label, -1, sizeof label);
  for (int i = 1; i <= n; i++) {
    if (groups[i].empty()) continue;
    if (groups[i].size() == 1) {
      label[groups[i][0]] = !a[i];
    } else {
      int aa = groups[i][0], b = groups[i][1];
      g[aa].push_back(make_pair(b, a[i]));
      g[b].push_back(make_pair(aa, a[i]));
    }
  }
  for (int i = 1; i <= k; i++) {
    if (vis[i]) continue;
    if (label[i] != -1) dfs(i, -1);
  }
  for (int i = 1; i <= k; i++) {
    if (vis[i]) continue;
    label[i] = 0;
    dfs(i, -1);
  }
  for (int i = 1; i <= k; i++) {
    par[i] = i, fix[i] = -1;
    sz[i][label[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (groups[i].size() == 1) {
      int no = groups[i][0], np = ro(no);
      if (a[i] == 0)
        fix[np] = label[no];
      else
        fix[np] = !label[no];
      res += sz[np][fix[np]] - cost[np];
      cost[np] = sz[np][fix[np]];
    } else if (groups[i].size() == 2) {
      int f = groups[i][0], s = groups[i][1];
      int fp = ro(f), sp = ro(s);
      if (fp != sp) {
        if (a[i] == 0) {
          sz[fp][!label[f]] += sz[sp][label[s]];
          sz[fp][label[f]] += sz[sp][!label[s]];
        } else {
          sz[fp][label[f]] += sz[sp][label[s]];
          sz[fp][!label[f]] += sz[sp][!label[s]];
        }
        if (fix[sp] != -1) {
          if (a[i] == 0) {
            if (label[s] == fix[sp])
              fix[fp] = !label[f];
            else
              fix[fp] = label[f];
          } else {
            if (label[s] == fix[sp])
              fix[fp] = label[f];
            else
              fix[fp] = !label[f];
          }
        }
        if (fix[fp] != -1) {
          res += sz[fp][fix[fp]] - (cost[fp] + cost[sp]);
          cost[fp] = sz[fp][fix[fp]];
        } else {
          res += min(sz[fp][0], sz[fp][1]) - (cost[fp] + cost[sp]);
          cost[fp] = min(sz[fp][0], sz[fp][1]);
        }
        par[sp] = fp;
      }
    }
    printf("%d\n", res);
  }
}
