fun main(args: Array<String>) = ABC160B.main()

object ABC160B {
    fun main() {
        val x = readLong()
        val n1 = x / 500
        val r1 = x % 500
        val n2 = r1 / 5

        val ans = n1 * 1000 + n2 * 5
        println(ans)
    }


    /*####################################################################################*/

    fun readLong() = readLine()!!.toLong()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
}