class A def initialize n, m = gets.chomp.split(' ').map(&:to_i) shaffle = gets.chomp.split(' ').map(&:to_i) cards = [*(1..n)] shaffle.each do |i| num = cards.delete_at(i-1) cards.unshift(num) end puts cards.first end end A.new