#include <bits/stdc++.h>
using namespace std;
template <typename T>
void _read(T& t);
template <typename T>
void _read(vector<T>& v);
template <typename T1, typename T2>
void _read(pair<T1, T2>& p);
template <typename T>
void _read(T& t) {
  cin >> t;
}
template <typename T>
void _read(vector<T>& v) {
  for (unsigned _i = 0; _i < v.size(); _i++) _read(v[_i]);
}
template <typename T1, typename T2>
void _read(pair<T1, T2>& p) {
  _read(p.first);
  _read(p.second);
}
void _masterread() {}
template <typename T, typename... V>
void _masterread(T& t, V&... v) {
  _read(t);
  _masterread(v...);
}
stringstream _effout;
template <typename T>
void _print(T t);
template <typename T>
void _print(vector<T>& v);
template <typename T1, typename T2>
void _print(pair<T1, T2>& p);
template <typename T>
void _print(T t) {
  _effout << t;
}
template <typename T>
void _print(vector<T>& v) {
  for (unsigned _i = 0; _i < v.size(); _i++)
    _print(v[_i]), _effout << (_i == v.size() - 1 ? "" : " ");
}
template <typename T1, typename T2>
void _print(pair<T1, T2>& p) {
  _print(p.first);
  _effout << " ";
  _print(p.second);
}
void _masterprint() {}
template <typename T, typename... V>
void _masterprint(T t, V... v) {
  _print(t);
  if (sizeof...(v)) _effout << " ";
  _masterprint(v...);
}
template <typename T>
void _debug(T t);
template <typename T1, typename T2>
void _debug(pair<T1, T2> p);
template <typename T>
void _debug(vector<T> v);
template <typename T>
void _debug(set<T> s);
template <typename T>
void _debug(unordered_set<T> s);
template <typename T>
void _debug(multiset<T> s);
template <typename T>
void _debug(unordered_multiset<T> s);
template <typename T1, typename T2>
void _debug(map<T1, T2> mp);
template <typename T1, typename T2>
void _debug(unordered_map<T1, T2> mp);
template <typename T1, typename T2>
void _debug(multimap<T1, T2> mp);
template <typename T1, typename T2>
void _debug(unordered_multimap<T1, T2> mp);
template <typename T>
void _debug(T t) {
  cerr << t;
}
template <typename T1, typename T2>
void _debug(pair<T1, T2> p) {
  cerr << "{";
  _debug(p.first);
  cerr << ", ";
  _debug(p.second);
  cerr << "}";
}
template <typename T>
void _debug(vector<T> v) {
  cerr << "(";
  for (unsigned _i = 0; _i < v.size(); _i++)
    _debug(v[_i]), cerr << (_i == v.size() - 1 ? "" : ", ");
  cerr << ")";
}
template <typename T>
void _debug(set<T> s) {
  cerr << "(";
  for (auto e = s.begin(); e != s.end();)
    _debug(*e), cerr << ((++e) == s.end() ? "" : ", ");
  cerr << ")";
}
template <typename T>
void _debug(unordered_set<T> s) {
  cerr << "(";
  for (auto e = s.begin(); e != s.end();)
    _debug(*e), cerr << ((++e) == s.end() ? "" : ", ");
  cerr << ")";
}
template <typename T>
void _debug(multiset<T> s) {
  cerr << "(";
  for (auto e = s.begin(); e != s.end();)
    _debug(*e), cerr << ((++e) == s.end() ? "" : ", ");
  cerr << ")";
}
template <typename T>
void _debug(unordered_multiset<T> s) {
  cerr << "(";
  for (auto e = s.begin(); e != s.end();)
    _debug(*e), cerr << ((++e) == s.end() ? "" : ", ");
  cerr << ")";
}
template <typename T1, typename T2>
void _debug(map<T1, T2> mp) {
  cerr << "(";
  for (auto e = mp.begin(); e != mp.end();)
    _debug(*e), cerr << ((++e) == mp.end() ? "" : ", ");
  cerr << ")";
}
template <typename T1, typename T2>
void _debug(unordered_map<T1, T2> mp) {
  cerr << "(";
  for (auto e = mp.begin(); e != mp.end();)
    _debug(*e), cerr << ((++e) == mp.end() ? "" : ", ");
  cerr << ")";
}
template <typename T1, typename T2>
void _debug(multimap<T1, T2> mp) {
  cerr << "(";
  for (auto e = mp.begin(); e != mp.end();)
    _debug(*e), cerr << ((++e) == mp.end() ? "" : ", ");
  cerr << ")";
}
template <typename T1, typename T2>
void _debug(unordered_multimap<T1, T2> mp) {
  cerr << "(";
  for (auto e = mp.begin(); e != mp.end();)
    _debug(*e), cerr << ((++e) == mp.end() ? "" : ", ");
  cerr << ")";
}
void _masterdebug() { cerr << "]" << endl; }
template <typename T, typename... V>
void _masterdebug(T t, V... v) {
  _debug(t);
  if (sizeof...(v)) cerr << ", ";
  _masterdebug(v...);
}
void _solve();
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  _masterprint(setprecision(10));
  _masterprint(fixed);
  _solve();
  cout << _effout.str();
}
void _test();
void _solve() {
  if (0) {
    signed __T;
    cin >> __T;
    while (__T--) _test();
  } else {
    _test();
  }
}
void _test() {
  int n, k;
  _masterread(n, k);
  string s;
  _masterread(s);
  vector<set<int>> adj(k);
  vector<vector<int>> sets(n);
  vector<vector<int>> subsets(k);
  for (int i = 0; i < k; i++) {
    int c;
    _masterread(c);
    for (int j = 0; j < c; j++) {
      int v;
      _masterread(v);
      v--;
      sets[v].push_back(i);
      subsets[i].push_back(v);
    }
  }
  for (int i = 0; i < k; i++) {
    for (auto& v : subsets[i]) {
      for (auto& node : sets[v]) {
        if (node != i) {
          adj[i].insert(node);
        }
      }
    }
  }
  auto answer = [&](string s) -> vector<int> {
    vector<int> color(k, 1), component(k), usedcolor(k), cntneg(k),
        cntpos(k, 1);
    vector<vector<int>> components(k);
    for (int i = 0; i < k; i++) components[i] = {i}, component[i] = i;
    vector<int> ans(n, INT_MAX);
    int ANS = 0;
    bool flag = 0;
    auto flip = [&](int comp) {
      usedcolor[comp] *= -1;
      for (auto& node : components[comp]) color[node] *= -1;
      swap(cntneg[comp], cntpos[comp]);
    };
    auto getans = [&](int comp) {
      if (usedcolor[comp] == 0)
        return min(cntneg[comp], cntpos[comp]);
      else if (usedcolor[comp] == 1)
        return cntpos[comp];
      else
        return cntneg[comp];
    };
    auto move = [&](int comp, int newcomp) {
      for (auto& node : components[comp])
        component[node] = newcomp, components[newcomp].push_back(node);
      ANS -= getans(comp);
      ANS -= getans(newcomp);
      cntneg[newcomp] += cntneg[comp];
      cntpos[newcomp] += cntpos[comp];
      if (usedcolor[comp] != usedcolor[newcomp] && usedcolor[comp] != 0 &&
          usedcolor[newcomp] != 0)
        flag = 1;
      if (usedcolor[comp] != 0) usedcolor[newcomp] = usedcolor[comp];
      ANS += getans(newcomp);
    };
    auto merge = [&](int a, int b, bool same) {
      if (component[a] == component[b]) {
        if (same && color[a] != color[b]) flag = 1;
        if (!same && color[a] == color[b]) flag = 1;
      } else {
        if (components[component[a]].size() > components[component[b]].size())
          swap(a, b);
        if (same && color[a] != color[b]) flip(component[a]);
        if (!same && color[a] == color[b]) flip(component[a]);
        move(component[a], component[b]);
      }
    };
    for (int i = 0; i < n; i++) {
      flag = 0;
      if (s[i] == '0' && sets[i].size() == 0) {
        flag = 1;
        return ans;
      }
      if (s[i] == '1') {
        if (sets[i].size() == 2) {
          int a = *sets[i].begin(), b = *sets[i].rbegin();
          merge(a, b, 1);
        } else if (sets[i].size() == 1) {
          int node = *sets[i].begin();
          if (usedcolor[component[node]] != 0 &&
              usedcolor[component[node]] == color[node])
            flag = 1;
          ANS -= getans(component[node]);
          usedcolor[component[node]] = color[node] * -1;
          ANS += getans(component[node]);
        }
      } else {
        if (sets[i].size() == 2) {
          int a = *sets[i].begin(), b = *sets[i].rbegin();
          merge(a, b, 0);
        } else {
          int node = *sets[i].begin();
          if (usedcolor[component[node]] != 0 &&
              usedcolor[component[node]] != color[node])
            flag = 1;
          ANS -= getans(component[node]);
          usedcolor[component[node]] = color[node];
          ANS += getans(component[node]);
        }
      }
      if (flag) return ans;
      ans[i] = ANS;
    }
    return ans;
  };
  auto a1 = answer(s);
  (_masterprint(a1), _effout << endl);
  return;
  for (auto& e : s) {
    if (e == '1')
      e = '0';
    else
      e = '1';
  }
  auto a2 = answer(s);
  for (int i = 0; i < n; i++) {
    (_masterprint(min(a1[i], a2[i])), _effout << endl);
  }
}
