#include <bits/stdc++.h>
using namespace std;
namespace IO {
template <class T>
inline void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
}
};  // namespace IO
const int N = 600005;
char ch[N];
int n, m, a[N], num[N], fa[N], flag[N];
long long size[N], ans;
vector<int> sset[N], fr[N];
inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
inline void uni(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx != fy) {
    fa[fx] = fy;
    size[fy] += size[fx];
  }
}
inline void Add(int x, int xval, int y, int yval) {
  x = x * 2 + xval;
  y = y * 2 + yval;
  uni(x, y);
}
const int oo = 3e8 + 1;
int main() {
  scanf("%d %d\n", &n, &m);
  scanf("%s\n", ch + 1);
  for (int i = (1); i <= (n); ++i) a[i] = ch[i] - '0';
  int tx;
  for (int i = (1); i <= (m); ++i) {
    scanf("%d\n", &num[i]);
    for (int j = (1); j <= (num[i]); ++j) {
      scanf("%d ", &tx);
      sset[i].push_back(tx);
      fr[tx].push_back(i);
    }
  }
  for (int i = (1); i <= (m); ++i) size[i * 2 + 1] = 1;
  for (int i = (1); i <= (m); ++i) fa[i * 2] = i * 2, fa[i * 2 + 1] = i * 2 + 1;
  for (int i = (1); i <= (n); ++i) {
    if (fr[i].size() < 1) {
      printf("%lld\n", ans);
      continue;
    }
    if (a[i]) {
      if (fr[i].size() == 1) {
        if (flag[find(fr[i][0] * 2 + 1)])
          ans -= size[find(fr[i][0] * 2 + 1)], flag[find(fr[i][0] * 2 + 1)] = 0;
        if (flag[find(fr[i][0] * 2)])
          ans -= size[find(fr[i][0] * 2)], flag[find(fr[i][0] * 2)] = 0;
        ans += size[find(fr[i][0] * 2)];
        flag[find(fr[i][0] * 2)] = 1;
        size[find(fr[i][0] * 2 + 1)] = oo;
      } else {
        if (flag[find(fr[i][0] * 2 + 1)])
          ans -= size[find(fr[i][0] * 2 + 1)], flag[find(fr[i][0] * 2 + 1)] = 0;
        if (flag[find(fr[i][0] * 2)])
          ans -= size[find(fr[i][0] * 2)], flag[find(fr[i][0] * 2)] = 0;
        if (flag[find(fr[i][1] * 2 + 1)])
          ans -= size[find(fr[i][1] * 2 + 1)], flag[find(fr[i][1] * 2 + 1)] = 0;
        if (flag[find(fr[i][1] * 2)])
          ans -= size[find(fr[i][1] * 2)], flag[find(fr[i][1] * 2)] = 0;
        Add(fr[i][0], 0, fr[i][1], 0);
        Add(fr[i][0], 1, fr[i][1], 1);
        if (size[find(fr[i][0] * 2)] > size[find(fr[i][0] * 2 + 1)]) {
          ans += size[find(fr[i][0] * 2 + 1)];
          flag[find(fr[i][0] * 2 + 1)] = 1;
        } else {
          ans += size[find(fr[i][0] * 2)];
          flag[find(fr[i][0] * 2)] = 1;
        }
      }
    } else {
      if (fr[i].size() == 1) {
        if (flag[find(fr[i][0] * 2 + 1)])
          ans -= size[find(fr[i][0] * 2 + 1)], flag[find(fr[i][0] * 2 + 1)] = 0;
        if (flag[find(fr[i][0] * 2)])
          ans -= size[find(fr[i][0] * 2)], flag[find(fr[i][0] * 2)] = 0;
        ans += size[find(fr[i][0] * 2 + 1)];
        flag[find(fr[i][0] * 2 + 1)] = 1;
        size[find(fr[i][0] * 2)] = oo;
      } else {
        if (flag[find(fr[i][0] * 2 + 1)])
          ans -= size[find(fr[i][0] * 2 + 1)], flag[find(fr[i][0] * 2 + 1)] = 0;
        if (flag[find(fr[i][0] * 2)])
          ans -= size[find(fr[i][0] * 2)], flag[find(fr[i][0] * 2)] = 0;
        if (flag[find(fr[i][1] * 2 + 1)])
          ans -= size[find(fr[i][1] * 2 + 1)], flag[find(fr[i][1] * 2 + 1)] = 0;
        if (flag[find(fr[i][1] * 2)])
          ans -= size[find(fr[i][1] * 2)], flag[find(fr[i][1] * 2)] = 0;
        Add(fr[i][0], 0, fr[i][1], 1);
        Add(fr[i][0], 1, fr[i][1], 0);
        if (size[find(fr[i][0] * 2)] > size[find(fr[i][0] * 2 + 1)]) {
          ans += size[find(fr[i][0] * 2 + 1)];
          flag[find(fr[i][0] * 2 + 1)] = 1;
        } else {
          ans += size[find(fr[i][0] * 2)];
          flag[find(fr[i][0] * 2)] = 1;
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
