#include <bits/stdc++.h>
using namespace std;
long long n, k;
bool start[300010];
vector<long long> ribs[300010];
vector<pair<long long, long long>> g[300010];
long long ans;
long long dsu[300010];
long long the_same[300010];
long long component_cost[300010][2];
void clear(long long u) {
  dsu[u] = u;
  the_same[u] = true;
  component_cost[u][0] = 0;
  component_cost[u][1] = 1;
}
void set_father(long long u) {
  the_same[u] = the_same[u] == the_same[dsu[u]];
  dsu[u] = dsu[dsu[u]];
}
void father(long long u) {
  if (dsu[u] == u) return;
  father(dsu[u]);
  set_father(u);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (long long i = 1; i <= n; ++i) {
    char x;
    cin >> x;
    start[i] = x - '0';
  }
  for (long long i = 1; i <= k; ++i) {
    long long m;
    cin >> m;
    for (long long j = 0; j < m; ++j) {
      long long x;
      cin >> x;
      ribs[x].push_back(i);
      if (ribs[x].size() == 2) {
        g[i].push_back({ribs[x][0], x});
        g[ribs[x][0]].push_back({i, x});
      }
    }
    clear(i);
    component_cost[i][0] = 0;
    component_cost[i][1] = 1;
  }
  for (long long i = 1; i <= n; ++i) {
    if (ribs[i].size() == 0) {
      cout << ans << '\n';
      continue;
    }
    if (ribs[i].size() == 1) {
      long long u = ribs[i][0];
      father(u);
      auto fath = dsu[u];
      ans -= min(component_cost[fath][0], component_cost[fath][1]);
      if (start[i]) {
        if (the_same[u]) {
          component_cost[fath][1] = 1e9;
        } else {
          component_cost[fath][0] = 1e9;
        }
      } else {
        if (the_same[u]) {
          component_cost[fath][0] = 1e9;
        } else {
          component_cost[fath][1] = 1e9;
        }
      }
      ans += min(component_cost[fath][0], component_cost[fath][1]);
      cout << ans << '\n';
      continue;
    }
    long long u = ribs[i][0];
    long long v = ribs[i][1];
    father(u);
    father(v);
    if (dsu[u] != dsu[v]) {
      ans -= min(component_cost[dsu[u]][0], component_cost[dsu[u]][1]) +
             min(component_cost[dsu[v]][0], component_cost[dsu[v]][1]);
      if (start[i]) {
        if (the_same[u] == the_same[v]) {
          component_cost[dsu[u]][0] += component_cost[dsu[v]][0];
          component_cost[dsu[u]][1] += component_cost[dsu[v]][1];
        } else {
          component_cost[dsu[u]][0] += component_cost[dsu[v]][1];
          component_cost[dsu[u]][1] += component_cost[dsu[v]][0];
          the_same[dsu[v]] = !the_same[dsu[v]];
        }
      } else {
        if (the_same[u] == the_same[v]) {
          component_cost[dsu[u]][0] += component_cost[dsu[v]][1];
          component_cost[dsu[u]][1] += component_cost[dsu[v]][0];
          the_same[dsu[v]] = !the_same[dsu[v]];
        } else {
          component_cost[dsu[u]][0] += component_cost[dsu[v]][0];
          component_cost[dsu[u]][1] += component_cost[dsu[v]][1];
        }
      }
      dsu[dsu[v]] = dsu[u];
      ans += min(component_cost[dsu[u]][0], component_cost[dsu[u]][1]);
    }
    cout << ans << '\n';
  }
  return 0;
}
