function Main (X) {
  X = parseInt(X.split("\n")[0], 10);
  var ft = Math.floor(X/500);
  X %= 500;
  var fo = Math.floor(X/5);
  console.log((ft * 1000) + (fo * 5));
}

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