//Nim

#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstring>
#define clr(a,v) memset((a),(v),sizeof(a))
const int MAX_N = 10, MAX_S = 1 << 13;

int n, S, M[2 * MAX_N];
int dp[2 * MAX_N][MAX_S + 1];

bool rec(int i, int j){
	if (j <= 1)return false;
	int &ret = dp[i][j];
	if (ret != -1)return ret;
	for (int k = 1; k <= M[i]; ++k){
		if (j - k >= 1){
			if (!rec((i + 1) % (n << 1), j - k))return ret = true;
		}
	}
	return ret = false;
}

int main(){
	while (scanf("%d", &n), n){
		scanf("%d", &S);
		for (int i = 0; i < (n << 1); ++i){
			scanf("%d", M + i);
		}
		clr(dp, -1);
		printf("%d\n", rec(0, S));

	}
	return 0;
}