fun main(args: Array<String>) {
    var money: Int = Integer.valueOf(readLine())
    var a: Int = money / 500
    var b: Int = (money - a * 500) / 5
    var ans = 1000 * a + 5 * b
    println(ans)
}

