fun main(args:Array<String>) {
    var x = readLine()!!.toInt()
    var ans = 0
    val cnt500 = x / 500
    x %= 500
    ans += cnt500 * 1000
    val cnt5 = x / 5
    ans += cnt5 * 5
    print(ans)
}
