function main(input) {
    var x = parseInt(input.trim().split(" "), 10);

    var num_500 = Math.floor(x/500);
    var num_5 = Math.floor((x-(num_500*500)) / 5);

    console.log(1000*num_500 + 5 * num_5);
}

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