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

const double h = 0.5;

void foo() {
    int n, r;
    cin >> n >> r;
    vector<double> w(n, 1);
    for (int round = 0; round < r; round++) {
        string s;
        cin >> s;
        double q1 = 0;
        double W = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == '1') {
                q1 += w[i];
            }
            W += w[i];
        }
        double p = (double) rand() / RAND_MAX;
        int my = p < (double) q1 / W;
        cout << my << endl;
        int ans;
        cin >> ans;
        W = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] - '0' != ans) { // wrong
                w[i] *= 1 - h;
            }
            W += w[i];
        }
        if (W < 0.1 * n) {
            for (int i = 0; i < n; i++) {
                w[i] *= 2;
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    srand(time(0));
    foo();
}
