function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    var X = input;
    var happy1 = 0;
    var happy2 = 0;
    var yen500 = X % 500;
    var yen5 = yen500 % 5;
    happy1 = (X - yen500) * 2;
    happy2 = yen500 - yen5;
    var happy = happy1 + happy2;
    console.log(happy);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));