while line = gets
  n,r = line.split.map(&:to_i)
  deck=(0..n-1).to_a
  cs  = gets.split.map(&:to_i)
  cs.each do |c|
    a = deck[n/2..n-1]
    b = deck[0...n/2]
    deck =[]
    until a.empty? && b.empty?
      c.times do
        if tmp =a.shift
          deck.push(tmp)
        end
      end
      c.times do
        if tmp = b.shift
          deck.push(tmp)
        end
      end
    end
  end
  p deck[-1]
end