#include <bits/stdc++.h>
using namespace std;
int pai[600005];
long long res, sz[600005];
vector<int> adj[600005];
int findpai(int u) { return (pai[u] == u ? u : pai[u] = findpai(pai[u])); }
void unionset(int x, int y) {
  x = findpai(x);
  y = findpai(y);
  if (x == y) return;
  ;
  res -= min(sz[x], sz[x ^ 1]);
  res -= min(sz[y], sz[y ^ 1]);
  pai[x] = y;
  sz[y] += sz[x];
  res += min(sz[y], sz[y ^ 1]);
  sz[x] = 0;
}
int main() {
  cout.sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  s = "$" + s;
  for (int i = 1; i <= k; i++) {
    int x;
    cin >> x;
    while (x--) {
      int u;
      cin >> u;
      adj[u].push_back(i);
    }
  }
  for (int i = 0; i < 600005; i++) {
    pai[i] = i;
    sz[i] = i % 2;
  }
  for (int i = 1; i <= n; i++) {
    if (adj[i].size() == 0) {
      cout << res << endl;
      continue;
    } else if (adj[i].size() == 1) {
      int u = adj[i][0];
      int aux = (s[i] == '1' ? findpai(u << 1 | 1) : findpai(u << 1));
      res -= min(sz[aux], sz[aux ^ 1]);
      sz[aux] = 1e9;
      res += sz[aux ^ 1];
    } else {
      int u = adj[i][0], v = adj[i][1];
      if (s[i] == '1') {
        unionset(u << 1, v << 1);
        unionset(u << 1 | 1, v << 1 | 1);
      } else {
        unionset(u << 1, v << 1 | 1);
        unionset(u << 1 | 1, v << 1);
      }
    }
    cout << res << endl;
  }
  return 0;
}
