program main
 implicit none
 integer X
 integer :: k500=0,k100=0,k50=0,k10=0,k5=0
 integer :: ure=0
 
 read *, X

 k500=X/500
 X=X-500*k500
!print *,X
 k5=X/5
 X=X-5*k5
!print *,X
 k100=X/100
 X=X-100*k100
!print *,X
 k50=X/50
 X=X-50*k50
!print *,X
 k10=X/10
 X=X-10*k10
!print *,X

 ure=1000*k500+5*k5

 print '(i0)', ure

endprogram main
