// input
function main(input) {
    let args = Number(input.split('\n')[0]);
    let total = 0;
    if (args === 0) {
        console.log(args);
    } else {
        total += Math.floor(Number(args / 500)) * 1000;
        args = Math.floor(Number(args % 500));
        total += Math.floor(Number(args / 5)) * 5;
        console.log(total);
    }
}

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