const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const X = lines[0] - 0

    const s = Math.floor(X / 500)
    const mod = Math.floor(X % 500)
    const f = Math.floor(mod / 5)

    console.log(s * 1000 + f * 5)

})(input)