"use strict";
function main(input) {
  const x = parseInt(input[0]);
  const en500 = Math.floor(x / 500);
  const en5  = Math.floor((x - en500*500) / 5);

  console.log(en500*1000 + en5*5);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));