while gets
n=$_.to_i
d=(0...n).to_a
r=gets.split.map(&:to_i)
r.each{|e|
a=d[n/2..-1]
b=d[0...n/2]
a2=[];a.each_slice(e){|f|a2<<f}
b2=[];b.each_slice(e){|f|b2<<f}
d=a2.zip(b2).flatten[0...n]
}
p d[n-1]
end