a = [*1..gets.to_i] gets.split.map{|i| a.unshift(a.slice!(i.to_i-1)) } puts a[0]