import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val x = scanner.nextInt()

    val _500 = x / 500
    val _5 = x % 500 / 5

    println(_500 * 1000 + _5 * 5)
}