#! ruby # yukicoder My Practice # author: Leornadone @ NEETSDKASU (N, M), A = $<.map{|x| x.chomp.split.map(&:to_i)} cards = (0..N).to_a M.times do |i| cards[0] = cards[A[i]] A[i].downto(1) do |j| cards[j] = cards[j - 1] end end puts cards[1]