import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int xx = x/500;
      	int num = x - xx*500;
      	int xxx = num/5;
      	int ans = xx*1000 + xxx*5;
        System.out.println(ans);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int xx = x/500;
      	int num = x - xx*500;
      	int xxx = num/5;
      	int ans = xx*1000 + xxx*5;
        System.out.println(ans);
	}
} Main public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int xx = x/500;
      	int num = x - xx*500;
      	int xxx = num/5;
      	int ans = xx*1000 + xxx*5;
        System.out.println(ans);
	} main {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int xx = x/500;
      	int num = x - xx*500;
      	int xxx = num/5;
      	int ans = xx*1000 + xxx*5;
        System.out.println(ans);
	} Scanner scn = new Scanner(System.in); scn new Scanner(System.in) int x = scn.nextInt(); x scn.nextInt() scn.nextInt scn int xx = x/500; xx x/500 x 500 int num = x - xx*500; num x - xx*500 x xx*500 xx 500 int xxx = num/5; xxx num/5 num 5 int ans = xx*1000 + xxx*5; ans xx*1000 + xxx*5 xx*1000 xx 1000 xxx*5 xxx 5 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int xx = x/500;
      	int num = x - xx*500;
      	int xxx = num/5;
      	int ans = xx*1000 + xxx*5;
        System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int xx = x/500;
      	int num = x - xx*500;
      	int xxx = num/5;
      	int ans = xx*1000 + xxx*5;
        System.out.println(ans);
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int xx = x/500;
      	int num = x - xx*500;
      	int xxx = num/5;
      	int ans = xx*1000 + xxx*5;
        System.out.println(ans);
	}
}