program main
      implicit none
      integer :: x, uresi
      read(*,*) x
      
      uresi = int(real(x)/real(500)) * 1000 + int(real(mod(x,500))/real(5)) * 5

      print *, uresi
end program main
