program sample
    implicit none
  
    integer(8) :: i,j,m,n,k,a,b,c,money
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n
    allocate(x(n))
    read(*,*)x
    money=1000
    c=0
    do i=1,n-1
        if(x(i)<x(i+1) .and. c==0)then
            a=x(i)
            b=money/x(i)
            c=1
        else if(x(i)>x(i+1) .and. c==1)then
            money=money+(x(i)-a)*b
            c=0
        end if
    end do
    if(c==1)then
        money=money+(x(n)-a)*b
    end if
    write(*,*)money

    
    stop
end program sample
  

