function main(input){
  let money = parseInt(input);
  let happy = 0;
  let happy2 = 0;
  let amari = money % 500
  
  
  while (money >= 500) {
      happy = money / 500;
  }

  happy = happy * 1000;
  
  while(amari >= 5){
    happy2 = amari / 5;
  } 

  happy2 = happy2 * 5;

  console.log(happy + happy2);
}

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