#include <bits/stdc++.h>
#define endl '\n'
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = 1e3 + 5;

string input;
int cnt[maxn], mx;
double a, b;

inline double randrand(){
    return (double ) rand() / RAND_MAX;
}

int main(){
    IOS;
    srand(time(nullptr));
    int n, m, c1, c2;
    char c;
    cin >> n >> m;
    for(int j = 0; j < m; j++){
        cin >> input;
        a = b = 0;
        if(j){
            for (int i = 0; i < n; i++){
                if (input[i] == '0') {
                    a += pow(0.9, cnt[i]);
                } else {
                    b += pow(0.9, cnt[i]);
                }
            }
        }
        if(a == b) cout << 1 << endl;
        else cout << (randrand() <= a / (a + b) ? 0 : 1) << endl;
        cout.flush();
        cin >> c;
        for(int i = 0; i < n; i++){
            cnt[i] += (input[i] != c);
        }
    }
}