#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, k, in[N], us[N];
bool on[N];
vector<int> lk[N], s[N];
void op(int st) {
  printf("Applied operation: ");
  for (int l : s[st]) printf("%d ", l);
  printf("\n");
}
void state() {
  printf("Current state: ");
  for (int i = 0; i < n; i++) {
    printf("%d", on[i]);
  }
  printf("\n");
}
int cost(int st) { return in[st] - 2 * us[st]; }
void combine(int sta, int stb) {
  if (stb != -1 and s[sta].size() > s[stb].size()) {
    swap(sta, stb);
  }
  for (int l : s[sta]) {
    lk[l].erase(std::remove(lk[l].begin(), lk[l].end(), sta), lk[l].end());
    if (stb != -1) {
      lk[l].push_back(stb);
      s[stb].push_back(l);
    }
    assert(lk[l].size() <= 2);
    if (lk[l].size() == 2 and lk[l][0] == lk[l][1]) lk[l].clear();
  }
  s[sta].clear();
  if (stb != -1) {
    in[stb] += in[sta];
    us[stb] += us[sta];
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    char c;
    scanf(" %c", &c);
    on[i] = (c == '1');
  }
  for (int i = 0; i < k; i++) {
    int sz;
    scanf("%d", &sz);
    for (int j = 0; j < sz; j++) {
      int x;
      scanf("%d", &x);
      --x;
      s[i].push_back(x);
      lk[x].push_back(i);
    }
    in[i] = 1;
    us[i] = 0;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int ln = lk[i].size();
    if (ln == 0) {
      assert(on[i]);
      printf("%d\n", cnt);
      continue;
    }
    if (!on[i]) {
      int st = lk[i][0];
      if (lk[i].size() >= 2 and cost(lk[i][1]) < cost(st)) st = lk[i][1];
      for (int l : s[st]) {
        on[l] ^= 1;
      }
      assert(on[i]);
      cnt += cost(st);
      us[st] = in[st] - us[st];
    }
    if (ln == 1) {
      int st = lk[i][0];
      combine(st, -1);
    }
    if (ln == 2) {
      int sta = lk[i][0], stb = lk[i][1];
      combine(sta, stb);
    }
    printf("%d\n", cnt);
  }
}
