#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


#define endl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(0,1e9);

//DEBUG FUNCTIONS START
#define cerr cout
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...)  _print(x)
#else
#define deb(x...)
#endif
// DEBUG FUNCTIONS END





const int N = 3e5 + 5;
int p[N], diff[N], par[N], szz[N], ans = 0;
pii sz[N];

int find(int u){
    if(u == p[u])
        return u;
    return p[u] = find(p[u]);
}

bool same(int u){
    if(u == par[u])
        return 1;
    return same(par[u]) ^ diff[u];
}

void join(int u, int v, bool same_col){

    int _u = find(u), _v = find(v);

    if(szz[_u] > szz[_v]){
        swap(u, v);
        swap(_u, _v);
    }

    if(_u != _v){

        p[_u] = _v;
        szz[_v] += szz[_u];

        if(!same(u))
            same_col ^= 1;
        if(!same(v))
            same_col ^= 1;

        ans -= min(sz[_u].fi, sz[_u].se);
        ans -= min(sz[_v].fi, sz[_v].se);

        if(same_col)
            sz[_v].fi += sz[_u].fi, sz[_v].se += sz[_u].se;
        else
            sz[_v].fi += sz[_u].se, sz[_v].se += sz[_u].fi;

        par[u] = v;
        diff[u] = !same_col;

        ans += min(sz[_v].fi, sz[_v].se);

    }

}

void solve(){

    
    int n, k;
    cin >> n >> k;
    vvi g(n+1);
    fr(i,1,k)
        p[i] = i, par[i] = i, sz[i] = {1, 0}, szz[i] = 1;

    string s;
    cin >> s;

    fr(i,1,k){
        int x;
        cin >> x;
        rep(_,0,x){
            int y;
            cin >> y;
            g[y].pb(i);
        }
    }


    fr(i,1,n){

        if(sz(g[i]) == 2){

            join(g[i][0], g[i][1], s[i-1] - '0');

        }

        else if(sz(g[i]) == 1){

            int col = !same(g[i][0]);
            int x = find(g[i][0]);
            ans -= min(sz[x].fi, sz[x].se);

            if(s[i-1] == '1'){
                if(col)
                    sz[x].se = infi, ans += sz[x].fi;
                else
                    sz[x].fi = infi, ans += sz[x].se;
            }
            else{
                if(col)
                    sz[x].fi = infi, ans += sz[x].se;
                else
                    sz[x].se = infi, ans += sz[x].fi;
            }

        }

        cout << ans << endl;
    }


}




signed main() {

    #ifndef ONLINE_JUDGE
        (void)!freopen("input.txt","r",stdin);
        (void)!freopen ("output.txt","w",stdout);
    #endif
    
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}


int powm(int a, int b){
    int res = 1;
    while (b) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

int divide(int a, int b) {
    return (a % mod) * powm(b % mod, mod - 2) % mod;
}