#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 3e5 + 5;
int n, k;
int d[maxn];
vector<int> v[maxn];
int ans = 0;
struct DSU {
  set<int> *c0, *c1;
  bool solved;
  DSU() {}
  DSU(int i) {
    c0 = new set<int>;
    c1 = new set<int>;
    c0->insert(i);
    solved = false;
  }
  int sz() { return c0->size() + c1->size(); }
  int which(int i) {
    assert(c0->count(i) || c1->count(i));
    return c0->count(i) ? 0 : 1;
  }
  int getCnt() {
    if (!solved) return min(c0->size(), c1->size());
    return c1->size();
  }
  void print() {
    cout << 0 << ": ";
    for (auto i : (*c0)) cout << i << ' ';
    cout << '\n';
    cout << 1 << ": ";
    for (auto i : (*c1)) cout << i << ' ';
    cout << '\n';
  }
};
DSU *dsu[maxn];
void Color(int i, int c) {
  if (dsu[i]->solved) {
    assert(c == dsu[i]->which(i));
    return;
  }
  ans -= dsu[i]->getCnt();
  int w = dsu[i]->which(i);
  if (w ^ c) swap(*(dsu[i]->c0), *(dsu[i]->c1));
  dsu[i]->solved = true;
  ans += dsu[i]->getCnt();
}
void Unify(int a, int b) {
  DSU *x = dsu[a], *y = dsu[b];
  if (x == y) return;
  int diff = x->which(a) ^ y->which(b);
  if (x->sz() < y->sz()) swap(x, y);
  ans -= x->getCnt();
  ans -= y->getCnt();
  bool nc = false;
  bool swapped = false;
  if (x->solved) {
    nc = true;
  } else if (y->solved) {
    nc = true;
    swapped = true;
  }
  if (!diff) {
    for (int i : *(y->c0)) {
      x->c1->insert(i);
      dsu[i] = x;
    }
    for (int i : *(y->c1)) {
      x->c0->insert(i);
      dsu[i] = x;
    }
  } else {
    for (int i : *(y->c0)) {
      x->c0->insert(i);
      dsu[i] = x;
    }
    for (int i : *(y->c1)) {
      x->c1->insert(i);
      dsu[i] = x;
    }
  }
  if ((!diff) && swapped) swap(*(x->c0), *(x->c1));
  x->solved = nc;
  ans += x->getCnt();
}
void Identify(int a, int b) {
  DSU *x = dsu[a], *y = dsu[b];
  if (x == y) return;
  int diff = x->which(a) ^ y->which(b);
  if (x->sz() < y->sz()) swap(x, y);
  ans -= x->getCnt();
  ans -= y->getCnt();
  bool nc = false;
  bool swapped = false;
  if (x->solved) {
    nc = true;
  } else if (y->solved) {
    nc = true;
    swapped = true;
  }
  if (!diff) {
    for (int i : *(y->c0)) {
      x->c0->insert(i);
      dsu[i] = x;
    }
    for (int i : *(y->c1)) {
      x->c1->insert(i);
      dsu[i] = x;
    }
  } else {
    for (int i : *(y->c0)) {
      x->c1->insert(i);
      dsu[i] = x;
    }
    for (int i : *(y->c1)) {
      x->c0->insert(i);
      dsu[i] = x;
    }
  }
  if (diff && swapped) swap(*(x->c0), *(x->c1));
  x->solved = nc;
  ans += x->getCnt();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    d[i] = s[i] - '0';
    d[i] ^= 1;
  }
  for (int i = 0; i < k; i++) {
    int c;
    cin >> c;
    while (c--) {
      int xi;
      cin >> xi;
      --xi;
      v[xi].push_back(i);
    }
  }
  for (int i = 0; i < k; i++) {
    dsu[i] = new DSU(i);
  }
  for (int i = 0; i < n; i++) {
    if (!d[i]) {
      if (v[i].size() == 1) {
        int a = v[i][0];
        Color(a, 0);
      } else if (v[i].size() == 2) {
        int a = v[i][0], b = v[i][1];
        Identify(a, b);
      }
    } else {
      if (v[i].size() == 1) {
        int a = v[i][0];
        Color(a, 1);
      } else if (v[i].size() == 2) {
        int a = v[i][0], b = v[i][1];
        Unify(a, b);
      }
    }
    cout << ans << '\n';
  }
}
