function main(input){
  var a = parseInt(input,10);
  var b = Math.floor(a / 500);
  var c = Math.floor((a%500)/5);
  var ans = b*1000 + c*5;
  console.log(ans);
}

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