program pr4
  implicit none
  integer :: n, i
  integer(8),allocatable :: a(:)
  integer(8) :: money, stock
  
  read(*,*) n
  allocate(a(n))
  read(*,*) a
  
  money = 1000_8
  stock = 0_8
  
  do i = 1, n-1
     if ( a(i) < a(i+1) ) then
        call  buystock(a(i), money, stock)
     else if ( a(i) > a(i+1) ) then
        call sellstock(a(i), money, stock)
     else
        cycle
     end if
  end do
  

  call sellstock(a(n),money,stock)
    
  write(*,'(i0)') money
  
  stop
contains

  subroutine buystock(price,money,stock)
    integer(8) :: price, money, stock
    do while ( money >= price )
       money = money - price
       stock = stock + 1_8
    end do
    return
  end subroutine buystock

  subroutine sellstock(price,money,stock)
    integer(8) :: price, money, stock
    do while ( stock > 0_8 )
       money = money + price
       stock = stock - 1_8
    end do
    return
  end subroutine sellstock
end program pr4
