#include <bits/stdc++.h>
using namespace std;
const int iinf = 1 << 29;
const long long inf = 1ll << 60;
const long long mod = 1e9 + 7;
void GG() {
  cout << "-1\n";
  exit(0);
}
long long mpow(long long a, long long n, long long mo = mod) {
  long long re = 1;
  while (n > 0) {
    if (n & 1) re = re * a % mo;
    a = a * a % mo;
    n >>= 1;
  }
  return re;
}
long long inv(long long b) {
  return b == 1 ? 1 : (mod - mod / b) * inv(mod % b) % mod;
}
const int maxn = 3e5 + 5;
bool arr[maxn];
int par[maxn];
int cst[maxn], c0[maxn], c1[maxn];
int dir[maxn];
bool def[maxn];
int n, k;
long long re = 0;
void setup() {
  for (int i = (0); i < (k); ++i) {
    par[i] = i;
    c0[i] = 1;
  }
}
int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
vector<pair<int, bool> > g[maxn];
void dfs(int v, int p = -1) {
  for (pair<int, bool> u : g[v]) {
    if (u.first != p) {
      dir[u.first] = dir[v] ^ u.second;
      dfs(u.first, v);
    }
  }
}
void setto(int a, bool x) {
  if (dir[a] == x) return;
  dir[a] = x;
  dfs(a);
  int A = find(a);
  swap(c0[A], c1[A]);
}
void Merge(int a, int b, bool TP) {
  int A = find(a), B = find(b);
  if (A == B || (def[A] && def[B])) return;
  ;
  if (def[A] != def[B]) {
    if (def[A]) {
      swap(A, B);
      swap(a, b);
    }
    setto(a, dir[b] ^ TP);
    re += (c1[A] - min(c0[A], c1[A]));
  } else if (!def[A] && !def[B]) {
    if (c0[A] + c1[A] > c0[B] + c1[B]) {
      swap(A, B);
      swap(a, b);
    }
    setto(a, dir[b] ^ TP);
    re -= min(c0[A], c1[A]) + min(c0[B], c1[B]);
  }
  c0[B] += c0[A];
  c1[B] += c1[A];
  if (!def[A] && !def[B]) {
    re += min(c0[B], c1[B]);
  }
  par[A] = B;
  g[a].push_back({b, TP});
  g[b].push_back({a, TP});
}
vector<int> in[maxn];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> k;
  setup();
  for (int i = (0); i < (n); ++i) {
    char c;
    cin >> c;
    arr[i] = c == '1';
  }
  for (int cnt = (0); cnt < (k); ++cnt) {
    int m;
    cin >> m;
    for (int i = (0); i < (m); ++i) {
      int x;
      cin >> x;
      x--;
      in[x].push_back(cnt);
    }
  }
  for (int i = (0); i < (n); ++i) {
    ;
    if ((int)in[i].size() == 1) {
      setto(in[i][0], arr[i] ^ 1);
      int fi = find(in[i][0]);
      if (!def[fi]) {
        def[fi] = 1;
        re += (c1[fi] - min(c0[fi], c1[fi]));
      }
    } else if ((int)in[i].size() == 2) {
      Merge(in[i][0], in[i][1], arr[i] ^ 1);
    }
    cout << re << '\n';
  }
}
