const main = (inputs) => {
  var yen = Number(inputs[0]);
  var ureshi = 0;
  ureshi = Math.floor(yen / 500) * 1000;
  yen = yen - Math.floor(yen / 500) * 1000;

  ureshi = ureshi + Math.floor(yen / 5) * 5;

  console.log(ureshi);
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));