'use strict';
function main(input) {
  let a = Number(input.trim().split('\n'));
  const Five = Math.floor(a / 500);
  a -= (500 * Five);
  const five = Math.floor(a / 5);
  
  console.log(1000 * Five + 5 * five);
}

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