process.stdin.resume();
process.stdin.setEncoding('utf8');

var input_string = "";

// Settings
var Y500 = 500;
//var Y100 = 100.0;
//var Y50  = 50.0;
//var Y10  = 10.0;
var Y5   = 5;
//var Y1   = 1.0;

var V500 = 1000;
var V5 = 5;
// output 
var value = 0;

var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

reader.on('line', (line) => {
    input_string = line;
    //convert number
    input_number = parseInt(input_string);

    var N500 = Math.floor(input_number / Y500); // 500円の枚数
    value += N500 * V500;
    input_number -= N500 * Y500;
    
    var N5 = Math.floor(input_number / Y5);
    value += N5 * V5;
    input_number -= N5 * Y5;

});

reader.on('close', () => {
    // output
    console.log(value);
});
