'use strict'
function main(inp) {
  let maney = inp*1;
  let ans = 0;
  if(maney >= 500){
  	ans += Math.floor(maney / 500)*1000;
    maney = maney%500;
  }
  if(maney >= 5){
    ans += Math.floor(maney / 5)*5;
  }
  console.log(ans);
}

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