import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int x = 0, y = 0;
		
		if(X>=500){
			x = X/500;
			X -= 500*x;
        }
		if(X>=5){
			y = X/5;
			X -= 5*y;
        }

		System.out.println(1000*x+5*y);
	}
} import java.util.*; util.* java public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int x = 0, y = 0;
		
		if(X>=500){
			x = X/500;
			X -= 500*x;
        }
		if(X>=5){
			y = X/5;
			X -= 5*y;
        }

		System.out.println(1000*x+5*y);
	}
} Main public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int x = 0, y = 0;
		
		if(X>=500){
			x = X/500;
			X -= 500*x;
        }
		if(X>=5){
			y = X/5;
			X -= 5*y;
        }

		System.out.println(1000*x+5*y);
	} main {
    	Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int x = 0, y = 0;
		
		if(X>=500){
			x = X/500;
			X -= 500*x;
        }
		if(X>=5){
			y = X/5;
			X -= 5*y;
        }

		System.out.println(1000*x+5*y);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int x = 0 x 0 y = 0; y 0 if(X>=500){
			x = X/500;
			X -= 500*x;
        } X>=500 X 500 {
			x = X/500;
			X -= 500*x;
        } x = X/500 x X/500 X 500 X -= 500*x X 500*x 500 x if(X>=5){
			y = X/5;
			X -= 5*y;
        } X>=5 X 5 {
			y = X/5;
			X -= 5*y;
        } y = X/5 y X/5 X 5 X -= 5*y X 5*y 5 y System.out.println(1000*x+5*y) System.out.println System.out System System.out 1000*x+5*y 1000*x 1000 x 5*y 5 y String[] args args public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int x = 0, y = 0;
		
		if(X>=500){
			x = X/500;
			X -= 500*x;
        }
		if(X>=5){
			y = X/5;
			X -= 5*y;
        }

		System.out.println(1000*x+5*y);
	}
} public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int x = 0, y = 0;
		
		if(X>=500){
			x = X/500;
			X -= 500*x;
        }
		if(X>=5){
			y = X/5;
			X -= 5*y;
        }

		System.out.println(1000*x+5*y);
	}
} Main
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int x = 0, y = 0;
		
		if(X>=500){
			x = X/500;
			X -= 500*x;
        }
		if(X>=5){
			y = X/5;
			X -= 5*y;
        }

		System.out.println(1000*x+5*y);
	}
}
