import java.util.Scanner;
public class Main {
	 public static void main(String args[]){
	Scanner scanner = new Scanner(System.in);

	int n=scanner.nextInt();
	int i=0;
	int m=0;

		
			i=n/500;
			n=n-500*i;
		
			m=n/5;
			
			System.out.println(1000*i+5*m);
	

	 }
} import java.util.Scanner; Scanner java.util public class Main {
	 public static void main(String args[]){
	Scanner scanner = new Scanner(System.in);

	int n=scanner.nextInt();
	int i=0;
	int m=0;

		
			i=n/500;
			n=n-500*i;
		
			m=n/5;
			
			System.out.println(1000*i+5*m);
	

	 }
} Main public static void main(String args[]){
	Scanner scanner = new Scanner(System.in);

	int n=scanner.nextInt();
	int i=0;
	int m=0;

		
			i=n/500;
			n=n-500*i;
		
			m=n/5;
			
			System.out.println(1000*i+5*m);
	

	 } main {
	Scanner scanner = new Scanner(System.in);

	int n=scanner.nextInt();
	int i=0;
	int m=0;

		
			i=n/500;
			n=n-500*i;
		
			m=n/5;
			
			System.out.println(1000*i+5*m);
	

	 } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n=scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int i=0; i 0 int m=0; m 0 i=n/500 i n/500 n 500 n=n-500*i n n-500*i n 500*i 500 i m=n/5 m n/5 n 5 System.out.println(1000*i+5*m) System.out.println System.out System System.out 1000*i+5*m 1000*i 1000 i 5*m 5 m String args[] args public class Main {
	 public static void main(String args[]){
	Scanner scanner = new Scanner(System.in);

	int n=scanner.nextInt();
	int i=0;
	int m=0;

		
			i=n/500;
			n=n-500*i;
		
			m=n/5;
			
			System.out.println(1000*i+5*m);
	

	 }
} public class Main {
	 public static void main(String args[]){
	Scanner scanner = new Scanner(System.in);

	int n=scanner.nextInt();
	int i=0;
	int m=0;

		
			i=n/500;
			n=n-500*i;
		
			m=n/5;
			
			System.out.println(1000*i+5*m);
	

	 }
} Main
import java.util.Scanner;
public class Main {
	 public static void main(String args[]){
	Scanner scanner = new Scanner(System.in);

	int n=scanner.nextInt();
	int i=0;
	int m=0;

		
			i=n/500;
			n=n-500*i;
		
			m=n/5;
			
			System.out.println(1000*i+5*m);
	

	 }
}