line = gets
prices = gets.split(' ').map(&:to_i)

have_money = 1000
kabu_num = 0

last_sell = false
prices.each_with_index do |price,i|
  break if prices[i+1].nil?

  if price < prices[i+1]
    # puts '買い'
    last_sell = true
    next if kabu_num != 0 # 株を保持してて買いの時はそのまま保持なので
    kabu_num = (have_money / price)
    have_money = have_money - (kabu_num * price)
  end
  
  if price > prices[i+1]
    # puts '売り'
    last_sell = false
    have_money = have_money + (kabu_num * price)
    kabu_num = 0
  end
end

# 最後
if last_sell
  have_money = have_money + (kabu_num * prices[-1])
end

