#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int , int> pii;
typedef long double ld;

const int N = 2e5+10 , mod = 1e9+7;

void solve(){
   int n , m;
   cin >> n >> m;
   double val[n];
   for(int i = 0 ; i < n ; i++){
      val[i] = 0;
   }
   for(int i = 0 ; i < m ; i++){
      string s;
      cin >> s;
      double v[2] = {0 , 0};
      int force_vote = -1;
      for(int j = 0 ; j < n ; j++){
         if(val[j] > 0)
            v[s[j] - '0'] += val[j] * val[j] * val[j] * val[j] * val[j];
         if(val[j] > 75){
            force_vote = s[j] - '0';
         }
      }
      int vt = 0;
      if(v[1] > v[0]){
         vt = 1;
      }
      if(force_vote != -1){
         vt = force_vote;
      }
      cout << vt << endl;
      int act;
      cin >> act;
      for(int j = 0 ; j < n ; j++){
         if(s[j] - '0' != vt){
            if(vt == act){
               val[j] -= 1.3;
            }
            else{
               val[j] += 1;
            }
         }
         else{
            if(vt != act){
               val[j] -= 0.3;
            }
         }
      }
   }
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int t = 1;
   //cin >> t;
   while(t--){
      solve();
   }
   return 0;
}
