fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val x = n % 500
    val a = (n-x)/500
    val y = x % 5
    val b = (x-y)/5
    var res = 0
    res += if (a > 0) a*1000 else 0
    res += if (b > 0) b*5 else 0
    println(res)
}