fun main(args: Array<String>) {
    var input = readLine()!!.toInt()
    var happy = 0

    happy += (input/500)
    input -= (500 * happy)
    happy *= 1000

    happy += (input/5) * 5
    print(happy)
}