import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var ar = scan.nextLong()
    var ans : Long = 0
    var temp : Long=0

    if(ar>=500){
        temp=ar/500
        ans+=(temp*1000)
        ar-=(temp*500)
    }
    if(ar>=5)
    {
        temp=ar/5
        ans+=(temp*5)
        ar-=(temp*5)
    }
    println(ans)

}
