n,m = gets.chomp.split.map{|str| str.to_i} shuffles = gets.chomp.split.map{|str| str.to_i} target = shuffles[m -1] (m - 2).downto(0) {|idx| tmp = shuffles[idx] if target == 1 target = tmp else if tmp < target next elsif tmp > target target -= 1 else target = 1 end end } puts target