import java.util.Scanner;

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

public class Main {
	  public static void main(String args[]){
	  	Scanner sc = new Scanner(System.in);
	    int x = sc.nextInt();
	    
	    int larger = x/500;
	    
	    int smaller = x - larger*500;
	    
	    int yens = smaller/5;
	    
	    System.out.println((larger * 1000) + (yens * 5));
	  }
	}
