#include <bits/stdc++.h>
using namespace std;
int N, K, sum;
string s;
vector<int> v[300301];
int p[600601], yes[600601], no[600601], fix[600601], now[600601];
int Find(int n) {
  if (n == p[n]) return n;
  return p[n] = Find(p[n]);
}
void Union(int a, int b) {
  a = Find(a);
  b = Find(b);
  if (a == b) return;
  p[a] = b;
  if (fix[a] != -1) fix[b] = fix[a];
  yes[b] += yes[a];
  no[b] += no[a];
  if (now[a] != -1) sum -= now[a];
  if (now[b] != -1) sum -= now[b];
  if (fix[b] == 1) {
    sum += yes[b];
    now[b] = yes[b];
  } else if (fix[b] == 0) {
    sum += no[b];
    now[b] = no[b];
  } else {
    if (yes[b] < no[b]) {
      sum += yes[b];
      now[b] = yes[b];
    } else {
      sum += no[b];
      now[b] = no[b];
    }
  }
}
int main() {
  for (int i = 0; i < 600601; i++) {
    p[i] = i;
    fix[i] = -1;
    now[i] = -1;
  }
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K >> s;
  for (int i = 1; i <= K; i++) {
    yes[i] = 1;
    no[i] = 0;
  }
  for (int i = 1; i <= K; i++) {
    yes[i + K] = 0;
    no[i + K] = 1;
  }
  for (int i = 1; i <= K; i++) {
    int t;
    cin >> t;
    for (int j = 0; j < t; j++) {
      int tt;
      cin >> tt;
      tt--;
      v[tt].push_back(i);
    }
  }
  for (int i = 0; i < N; i++) {
    if (v[i].size() == 2) {
      int a = v[i][0], b = v[i][1];
      if (s[i] == '0') {
        Union(a, b + K);
        Union(a + K, b);
      } else {
        Union(a, b);
        Union(a + K, b + K);
      }
    } else if (v[i].size() == 1) {
      int a = v[i][0];
      if (s[i] == '0') {
        int t = Find(a), f = Find(a + K);
        fix[t] = 1;
        fix[f] = 0;
        if (now[t] != -1) sum -= now[t];
        if (now[f] != -1) sum -= now[f];
        sum += yes[t];
        now[t] = yes[t];
        sum += no[f];
        now[f] = no[f];
      } else {
        int t = Find(a + K), f = Find(a);
        fix[t] = 1;
        fix[f] = 0;
        if (now[t] != -1) sum -= now[t];
        if (now[f] != -1) sum -= now[f];
        sum += yes[t];
        now[t] = yes[t];
        sum += no[f];
        now[f] = no[f];
      }
    } else if (v[i].size() == 0)
      ;
    else
      assert(0);
    cout << sum / 2 << "\n";
  }
  return 0;
}
