#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

#define LOSE 0
#define WIN  1
int table[20][(1<<14)];

int  solve(int n,int now,int *data,int num){
  if (table[now][num] != -1)return table[now][num];
  if (num == 0){
    return WIN;
  }
  
  int ret = LOSE;
  REP(i,1,1+data[now]){
    if (num-i<0)break;
    if (solve(n,(now+1)%n,data,num-i) == LOSE)ret =WIN;
  }
  return table[now][num]=ret;
}

int main(){
  int n,num;
  int data[20];
  while(cin>>n>>num && n){
    n*=2;
    rep(i,n)rep(j,num+1)table[i][j]=-1;
    rep(i,n)cin>>data[i];
    cout << solve(n,0,data,num) << endl;
  }
}