function main(input){
    num = parseInt(input);
    sen = 0;
    go = 0;
    sen = Math.floor(num/500);
    go = Math.floor((num - sen*500)/5);
    out = sen*1000 + go*5;
    console.log(out);

}

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