"use strict";

const main = (input) => {
    const spi = input.split('\n');
    let x = Number(spi[0]);
    let ans = Math.floor((x / 500)) * 1000;
    x %= 500;
    ans += Math.floor(x / 5) * 5;
    console.log(ans);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));
