gets # 不要なので捨て shuffles = gets.chomp.split.map{|str| str.to_i} target = 1 shuffles.reverse.each {|tmp| if target == 1 target = tmp next end if tmp < target next elsif tmp > target target -= 1 else target = 1 end } puts target