#include <bits/stdc++.h>
using namespace std;
int n, k, val[310000], g[310000], st;
bool state[310000], unchange[310000], rev[310000];
string s;
vector<int> sweet[310000];
bool fuck(int x) {
  if (rev[x]) return !state[g[x]];
  return state[g[x]];
}
int look(int x) {
  if (g[x] == x) return x;
  look(g[x]);
  if (rev[x])
    rev[x] = !rev[g[x]];
  else
    rev[x] = rev[g[x]];
  g[x] = look(g[x]);
  return g[x];
}
void unite(int x, int y, bool pos) {
  look(x);
  look(y);
  if (!rev[x]) pos = !pos;
  if (!rev[y]) pos = !pos;
  x = look(x);
  y = look(y);
  if (x == y) return;
  if (pos) {
    if (state[x] != state[y]) {
      if (unchange[x]) {
        st += val[y];
        val[x] -= val[y];
        g[y] = x;
        return;
      }
      if (unchange[y]) {
        st += val[x];
        val[y] -= val[x];
        g[x] = y;
        return;
      }
      if (val[x] > val[y]) {
        st += val[y];
        g[y] = x;
        val[x] -= val[y];
        return;
      } else {
        st += val[x];
        g[x] = y;
        val[y] -= val[x];
        return;
      }
    } else {
      g[y] = x;
      val[x] += val[y];
      if (unchange[y]) unchange[x] = true;
    }
  }
  if (!pos) {
    if (state[x] == state[y]) {
      if (unchange[x]) {
        st += val[y];
        val[x] -= val[y];
        g[y] = x;
        rev[y] = true;
        return;
      }
      if (unchange[y]) {
        st += val[x];
        val[y] -= val[x];
        g[x] = y;
        rev[x] = true;
        return;
      }
      if (val[x] > val[y]) {
        st += val[y];
        g[y] = x;
        rev[y] = true;
        val[x] -= val[y];
        return;
      } else {
        st += val[x];
        g[x] = y;
        rev[x] = true;
        val[y] -= val[x];
        return;
      }
    } else {
      g[y] = x;
      rev[y] = true;
      val[x] += val[y];
      if (unchange[y]) unchange[x] = true;
    }
  }
}
int main() {
  for (int i = 0; i < 310000; i++) {
    val[i] = 1;
    g[i] = i;
  }
  cin >> n >> k;
  cin >> s;
  for (int i = 1; i <= k; i++) {
    int tmp, fuck;
    cin >> tmp;
    for (int j = 0; j < tmp; j++) {
      cin >> fuck;
      sweet[fuck - 1].push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (sweet[i].size() == 1) {
      int a = sweet[i][0];
      int p = look(a);
      unchange[p] = true;
      if (s[i] == '0' && !fuck(a)) {
        st += val[p];
        val[p] = -val[p];
        state[p] = !state[p];
      }
      if (s[i] == '1' && fuck(a)) {
        st += val[p];
        val[p] = -val[p];
        state[p] = !state[p];
      }
    } else if (sweet[i].size() == 2) {
      int a = sweet[i][0];
      int b = sweet[i][1];
      if (s[i] == '0')
        unite(a, b, false);
      else
        unite(a, b, true);
    }
    cout << st << "\n";
  }
}
