"use strict";

const main = arg => {
    // 標準入力の不要な空白と改行を削除し、配列に格納する
    const input = arg.trim().split(" ");
    const money = parseInt(input[0]);

    const div500 = Math.floor(money / 500);
    const amari500 = money % 500;
    const div5 = Math.floor(amari500 / 5);

    const happiness = (div500 * 1000) + (div5 * 5);
    console.log(happiness);

}

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