#include<bits/stdc++.h>
using namespace std;
const int maxn=1005;
int wa[maxn]={0};

mt19937_64 mrand(time(0));
typedef long long ll;
ll myrand() {
    ll x = mrand();
    if(x<0)
        x = -x;
    return x;
}
ll pow(ll a,ll b){
    ll ans=1;
    for(int i=0;i<b;i++)ans*=a;
    return ans;
}
int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    while(m--){
        string s;
        cin>>s;
        int min_wa=1e9;
        for(int i=0;i<n;i++){
            min_wa=min(min_wa,wa[i]);
        }
        const int dif=20;
        ll tot=0,ac=0;
        for(int i=0;i<n;i++){
            if(min_wa+dif>=wa[i]){
                tot+=(pow(2,dif-(wa[i]-min_wa)));
                if(s[i]=='1')ac+=(pow(2,dif-(wa[i]-min_wa)));
            }
        }
        if((myrand()%tot)<ac){
            cout<<1<<endl;
        }
        else{
            cout<<0<<endl;
        }
        int ans;
        cin>>ans;
        for(int i=0;i<n;i++){
            wa[i]+=((s[i]-'0')!=ans);
        }
    }
}
