import java.util.*

fun main(args: Array<String>) {
    solve(java.util.Scanner(System.`in`))
}

fun solve(sc: java.util.Scanner) {
    val X = sc.nextInt()

    var x = X
    var ans = (X / 500) * 1000
    x %= 500
    ans += (x / 5) * 5

    println(ans)
}
