import java.util.*

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    var X = sc.nextInt()
    var result = (X / 500) * 1000
    result += ((X % 500) / 5) * 5
    print(result)
}
