fun main(args: Array<String>) {
    val price = readLine().orEmpty().toLong()
    var balance = 0L
    var glad = 0L


    if(price >= 500){
        glad += (price / 500) * 1000
        balance = price % 500
        if(balance >= 5){
            glad += (balance / 5) * 5
        }
    }else{
        glad += (price / 5) * 5
    }
    

    println(glad)
}