#include <bits/stdc++.h>

#define debug(...) fprintf(stderr ,__VA_ARGS__)
#define __FILE(x)\
	freopen(#x".in" ,"r" ,stdin);\
	freopen(#x".out" ,"w" ,stdout)
#define LL long long

const int MX = 1000 + 23;
const LL MOD = 998244353;

int read(){
	char k = getchar(); int x = 0;
	while(k < '0' || k > '9') k = getchar();
	while(k >= '0' && k <= '9') x = x * 10 + k - '0' ,k = getchar();
	return x;
}

int n ,m;
int wrong[MX];
char s[MX];

int cho(LL a ,LL b){
	double rd = 1.0 * rand() / RAND_MAX;
	return rd >= 1.0 * a / (a + b);
}

double p[MX];

void init(){
	p[0] = 2.2;
	for(int i = 1 ; i <= 20 ; ++i)
		p[i] = p[i - 1] * p[0];
}

int main(){
	init();
	srand(time(0));
	n = read() ,m = read();
	for(int i = 1 ; i <= m ; ++i){
		scanf("%s" ,s + 1);
		int best = m + 1 ,bcnt = 0;
		for(int j = 1 ; j <= n ; ++j){
			if(wrong[j] < best) best = wrong[j] ,bcnt = 0;
			if(wrong[j] == best) ++bcnt;
		}
		double choice[2] = {0 ,0};
		for(int j = 1 ; j <= n ; ++j){
			if(wrong[j] - best <= 10){
				choice[s[j] - '0'] += p[10 - (wrong[j] - best)];
			}
		}
		int should = cho(choice[0] ,choice[1]);

		printf("%d\n" ,should);
		fflush(stdout);
		int res = read();
		for(int j = 1 ; j <= n ; ++j)
			wrong[j] += res != s[j] - '0';
	}
	return 0;
}