import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
      	
      	int numberof500 = x/500;
        int remainder = x%500;
        int numberof5 = remainder/5;
      	long ans = 1000*numberof500+5*numberof5;
      
      System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
      	
      	int numberof500 = x/500;
        int remainder = x%500;
        int numberof5 = remainder/5;
      	long ans = 1000*numberof500+5*numberof5;
      
      System.out.println(ans);
	}
} Main public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
      	
      	int numberof500 = x/500;
        int remainder = x%500;
        int numberof5 = remainder/5;
      	long ans = 1000*numberof500+5*numberof5;
      
      System.out.println(ans);
	} main {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
      	
      	int numberof500 = x/500;
        int remainder = x%500;
        int numberof5 = remainder/5;
      	long ans = 1000*numberof500+5*numberof5;
      
      System.out.println(ans);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int x = in.nextInt(); x in.nextInt() in.nextInt in int numberof500 = x/500; numberof500 x/500 x 500 int remainder = x%500; remainder x%500 x 500 int numberof5 = remainder/5; numberof5 remainder/5 remainder 5 long ans = 1000*numberof500+5*numberof5; ans 1000*numberof500+5*numberof5 1000*numberof500 1000 numberof500 5*numberof5 5 numberof5 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[]) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
      	
      	int numberof500 = x/500;
        int remainder = x%500;
        int numberof5 = remainder/5;
      	long ans = 1000*numberof500+5*numberof5;
      
      System.out.println(ans);
	}
} public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
      	
      	int numberof500 = x/500;
        int remainder = x%500;
        int numberof5 = remainder/5;
      	long ans = 1000*numberof500+5*numberof5;
      
      System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
      	
      	int numberof500 = x/500;
        int remainder = x%500;
        int numberof5 = remainder/5;
      	long ans = 1000*numberof500+5*numberof5;
      
      System.out.println(ans);
	}
}
