#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = 998244353;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct Edge {
  int to, cap, rev;
  Edge(int _to, int _cap, int _rev) {
    to = _to;
    cap = _cap;
    rev = _rev;
  }
};
void add_edge(vector<vector<Edge>>& G, int from, int to, int cap, bool revFlag,
              int revCap) {
  G[from].push_back(Edge(to, cap, G[to].size()));
  if (revFlag) G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}
class UnionFind {
  vector<int> data;
  int num;

 public:
  UnionFind(int size) : data(size, -1), num(size) {}
  bool unionSet(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
      num--;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
  int numSet() { return num; }
};
void dfs(vector<vector<Edge>>& g, vector<long long>& use, int v) {
  for (auto e : g[v]) {
    if (use[e.to] != -1) continue;
    if (e.cap)
      use[e.to] = !use[v];
    else
      use[e.to] = use[v];
    dfs(g, use, e.to);
  }
}
void solve() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vvec<int> a(n);
  for (int(i) = (int)(0); (i) < (int)(k); (i)++) {
    long long c;
    cin >> c;
    for (int(j) = (int)(0); (j) < (int)(c); (j)++) {
      long long x;
      cin >> x;
      a[x - 1].push_back(i);
    }
  }
  vector<vector<Edge>> g(k + 1);
  for (int(i) = (int)(0); (i) < (int)(n); (i)++) {
    if (a[i].size() == 1) {
      a[i].push_back(k);
      if (s[i] == '0') {
        add_edge(g, a[i][0], k, 1, true, 1);
      } else {
        add_edge(g, a[i][0], k, 0, true, 0);
      }
    } else if (a[i].size() == 2) {
      if (s[i] == '0') {
        add_edge(g, a[i][0], a[i][1], 1, true, 1);
      } else {
        add_edge(g, a[i][0], a[i][1], 0, true, 0);
      }
    }
  }
  vector<long long> use(k + 1, -1);
  use[k] = 0;
  dfs(g, use, k);
  vector<long long> cost(k + 1, 0);
  for (int(i) = (int)(0); (i) < (int)(k); (i)++)
    if (use[i] == 1) cost[i] = 1;
  UnionFind uni(k + 1);
  vector<long long> cost_pre(k + 1, 0);
  long long ans = 0;
  for (int(i) = (int)(0); (i) < (int)(n); (i)++) {
    if (a[i].size() == 0) {
      cout << ans << '\n';
      if (k >= 300000) cout << "a" << '\n';
      continue;
    }
    int u = uni.root(a[i][0]);
    int v = uni.root(a[i][1]);
    if (uni.findSet(u, v)) {
      cout << ans << '\n';
      if (k >= 300000) cout << "b" << '\n';
      continue;
    }
    long long pre = cost_pre[u] + cost_pre[v];
    long long now = cost[u] + cost[v];
    long long size = uni.size(u) + uni.size(v);
    if (k >= 300000) cout << pre << " " << now << " " << size << '\n';
    uni.unionSet(u, v);
    ans -= pre;
    long long root = uni.root(u);
    cost[root] = now;
    if (uni.findSet(root, k)) {
      ans += now;
      cost_pre[root] = now;
    } else {
      ans += min(now, size - now);
      cost_pre[root] = min(now, size - now);
    }
    cout << ans << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
