'use strict';
function Main(input) {
  const coins = Number.parseInt(input, 10);
  let maxCoins500 = Math.floor(coins / 500);
  for (let i = maxCoins500; 0 <= i; --i) {
    for (let j = 0; j < 1000; ++j){
      const remain = coins - (500 * i + 5 * j);
      if (remain < 0 || remain < 5) {
        console.log(1000 * i + 5 * j);
        return;
      }
    }
  }
  console.log(0);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));