#include "bits/stdc++.h"
#define ll long long
#define lld long double
using namespace std;


 

 
int wrongs[1005];
string guesses;

int main() {
	int n,m;
	cin>>n>>m;

  ll l,r; //edges of distr
  for(int i = 0 ; i < m ; i++){
        cin >> guesses;
        l =0;
        r=0;
        
        int best=m+1;
        for (int j=0;j<n;j++){
            best=min(best,wrongs[j]);
        }
        
        for (int j=0;j<n;j++){
            if (wrongs[j]<=best+11){
              if ( guesses[j]-'0' == 0)
                l+=(1LL<<(best+11-wrongs[j]));
              else
                r+=(1LL<<(best+11-wrongs[j]));
            } 
        }
        
        //cout << l << "  " << r << endl;
        int rnd=1ll*rand()*rand()*rand()%(l+r)+1;
        if (rnd<=l) {
          cout << 0 << endl;
        }
        else {
          cout << 1 << endl;
        }
        
        
        
        fflush(stdout);
        
        
        
        int answer;
        cin >> answer;
        for (int j=0;j<n;j++)
        if (answer!=guesses[j]-'0') {
          wrongs[j]++;
        }



  }
 
	return 0;
}
