//100gods

#include <bits/stdc++.h>
#define int long long
#define vec2 vector<vector<int>>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define FRE freopen("elegant.in","r",stdin);freopen("elegant.out","w",stdout)
#define pii pair <int,int>
#define vii vector <int>
#define vpii vector <pii>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define minii LLONG_MAX
#define all(x) x.begin(), x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define double long double
#define eb emplace_back
const double pi = 3.1415926535898;
const int mod=1e9+7;
//const int mod=998244353;

using namespace std;

int32_t main()
{
    fio;
    int n,m;
    cin>>n>>m;
    double w[m+1];
    w[0]=1;
    for (int i=1;i<=m;i++)
    {
        w[i]=w[i-1]*(1/1.3);
    }
    int a[n];
    mem(a,0);
    while (m--)
    {
        string s;
        cin>>s;
        double val=0,tw=0;
        int x=1e18;
        for (int i=0;i<n;i++)
        {
            x=min(x,a[i]);
        }
        for (int i=0;i<n;i++)
        {
            val+=(s[i]-'0')*w[a[i]-x];
            tw+=w[a[i]-x];
        }
        val/=tw;
        double d = rand()/(double)RAND_MAX;
        if (d<=val)
        {
            cout<<"1"<<endl;
        }
        else
        {
            cout<<"0"<<endl;
        }
        int xx;
        cin>>xx;
        for (int i=0;i<n;i++)
        {
            if (xx!=s[i]-'0')
            {
                a[i]++;
            }
        }
    }
    return 0;
}
