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

const int N = 1e5 + 5;

int n, m, cnt[N], Min = 0;
char s[N];

int main() {
	cin >> n >> m;
	for(int i = 1; i <= m; ++ i) {
		scanf("%s", s + 1);
		Min = 1e9;
		for(int j = 1; j <= n; ++ j)
		Min = min(Min, cnt[j]);
		long double a0 = 0, a1 = 0;
		for(int j = 1; j <= n; ++ j) {
			if(s[j] == '0')
			a0 += pow(0.5, cnt[j] - Min);
			else a1 += pow(0.5, cnt[j] - Min);
		}
		double now = rand() / (double)RAND_MAX;
		if(now > a0 / (a0 + a1)) {
			puts("1");
		}
		else puts("0");
		fflush(stdout);
		int ans = 0; scanf("%d", &ans);
		for(int j = 1; j <= n; ++ j) {
			if((s[j] - '0') ^ (ans) == 0); else ++ cnt[j];
		}
	}
}