#include <bits/stdc++.h>
using namespace std;
const int mx = 1e9;
const long long mod = 1e9 + 7;
const int maxn = 3e5 + 10;
int n, k, ans;
int dat[maxn], w[maxn][2], flag[maxn], root[maxn], dis[maxn];
vector<int> lamp[maxn];
int find_root(int x) {
  if (root[x] == x) return root[x];
  int re = find_root(root[x]);
  dis[x] = dis[x] ^ dis[root[x]];
  root[x] = re;
  return re;
}
void add(int x, int y, int t) {
  int u, v;
  u = find_root(x);
  v = find_root(y);
  if (u == v) return;
  if (flag[u] == 0) {
    ans -= min(w[u][0], w[u][1]);
  } else if (flag[u] == 1) {
    ans -= w[u][1];
  } else {
    ans -= w[u][0];
  }
  if (flag[v] == 0) {
    ans -= min(w[v][0], w[v][1]);
  } else if (flag[v] == 1) {
    ans -= w[v][1];
  } else {
    ans -= w[v][0];
  }
  if (dis[x] != dis[y]) t ^= 1;
  root[v] = u;
  if (t == 0) {
    dis[v] = 1;
    if (flag[v] == -1) flag[u] = 1;
    if (flag[v] == 1) flag[u] = -1;
    w[u][0] += w[v][1];
    w[u][1] += w[v][0];
  } else {
    dis[v] = 0;
    if (flag[v] == 1) flag[u] = 1;
    if (flag[v] == -1) flag[u] = -1;
    w[u][0] += w[v][0];
    w[u][1] += w[v][1];
  }
  if (flag[u] == 0) {
    ans += min(w[u][0], w[u][1]);
  } else if (flag[u] == 1) {
    ans += w[u][1];
  } else {
    ans += w[u][0];
  }
}
void mark(int x, int t) {
  int u = find_root(x);
  if (flag[u] != 0) return;
  if (dis[x] == 1) t = -t;
  ans -= min(w[u][0], w[u][1]);
  flag[u] = t;
  if (t == 1)
    ans += w[u][1];
  else
    ans += w[u][0];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    dat[i] = c - '0';
  }
  for (int i = 1; i <= k; i++) {
    int sl;
    cin >> sl;
    for (int j = 1; j <= sl; j++) {
      int ls;
      cin >> ls;
      lamp[ls].push_back(i);
    }
    root[i] = i;
    w[i][0] = 0;
    w[i][1] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (dat[i] == 0) {
      if (lamp[i].size() == 1) {
        mark(lamp[i][0], 1);
      } else {
        add(lamp[i][0], lamp[i][1], 0);
      }
    } else {
      if (lamp[i].size() == 1) {
        mark(lamp[i][0], -1);
      } else if (lamp[i].size() == 2) {
        add(lamp[i][0], lamp[i][1], 1);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
