function Main(input) {
    input = input.split("\n");
  	var a = input[0]-0;
  	var aa = ~~(a/500);
  	var ans = 0;
  	ans += aa*1000;
  	var bb = ~~((a-aa*500)/5);
  	ans += bb*5;
  	console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));