"use strict"
function main(arg) {
    var n = Number(arg.trim().split("\n")[0])
    var a = Math.floor(n / 500)
    n = (n % 500)
    var b = Math.floor(n / 5)
    console.log(a * 1000 + b * 5)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));