#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> fails(n);
    for (int j = 0; j < m; j++) {
        string s;
        cin >> s;
        int mnf = 1e9;
        for (int x : fails) {
            mnf = min(mnf, x);
        }

        double sc0 = 0;
        double sc1 = 0;
        for (int i = 0; i < n; i++) {
            int f = fails[i] - mnf;
            double w = pow(0.5, f);
            if (s[i] == '0') {
                sc0 += w;
            } else {
                sc1 += w;
            }
        }

        double r = (sc0 + sc1) * rand() / RAND_MAX;

        int vote = r <= sc0 ? 0 : 1;
        cout << vote << endl;
        int actual;
        cin >> actual;
        for (int i = 0; i < n; i++) {
            int v = s[i] - '0';
            if (v != actual) {
                fails[i]++;
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed;
    cout.precision(12);

    srand(time(0));
    int T = 1;
    //cin >> T;
    for (int t = 0; t < T; t++) {
        solve();
    }

    return 0;
}
