### main

loop do
  ms = gets.split.map(&:to_i)

  n = ms.shift
  break if n == 0

  s = ms.shift

  n2 = n * 2

  wls = n2.times.map{(s + 1).times.map{nil}}
  (0...n2).each{|i| wls[i][1] = 0}

  for si in (2..s)
    for i in (0...n2)
      j = (i + 1) % n2
      for mi in (1..ms[i])
        si0 = si - mi
        break if si0 < 1
        if wls[j][si0] == 0
          wls[i][si] = 1
          break
        end
        wls[i][si] = 0 if wls[i][si].nil?
      end
    end
  end

  puts wls[0][s]
end