function main(input){
  let a = parseInt(input,10);
  let b = Math.floor(a / 500);
  let c = Math.floor((a%500)/5);

  console.log(b*1000 + c*5);
}

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