// B - Golden Coins
// https://atcoder.jp/contests/abc160/tasks/abc160_b


function Main(input) {
    const X = parseInt(input, 10);

    const count500 = X / 500;
    const modX = X % 500;
    const count5 = modX / 5;

    //出力
    console.log(count500 * 1000 + count5 * 5);
}

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