import java.util.Scanner;
public class Main{
    public static Scanner scn=new Scanner (System.in);
    public static void main(String []args){
        ans();
    }
    public static void ans(){
    int x=scn.nextInt();
    int a=(x/500 )*1000;
    int b=(x%500);
   b=b/5;
   b=b*5;
    System.out.print(a+b);

    
    }
}
   import java.util.Scanner; Scanner java.util public class Main{
    public static Scanner scn=new Scanner (System.in);
    public static void main(String []args){
        ans();
    }
    public static void ans(){
    int x=scn.nextInt();
    int a=(x/500 )*1000;
    int b=(x%500);
   b=b/5;
   b=b*5;
    System.out.print(a+b);

    
    }
} Main public static Scanner scn=new Scanner (System.in); scn new Scanner (System.in) public static void main(String []args){
        ans();
    } main {
        ans();
    } ans() ans String []args args public static void ans(){
    int x=scn.nextInt();
    int a=(x/500 )*1000;
    int b=(x%500);
   b=b/5;
   b=b*5;
    System.out.print(a+b);

    
    } ans {
    int x=scn.nextInt();
    int a=(x/500 )*1000;
    int b=(x%500);
   b=b/5;
   b=b*5;
    System.out.print(a+b);

    
    } int x=scn.nextInt(); x scn.nextInt() scn.nextInt scn int a=(x/500 )*1000; a (x/500 )*1000 (x/500 ) x 500 1000 int b=(x%500); b (x%500) x 500 b=b/5 b b/5 b 5 b=b*5 b b*5 b 5 System.out.print(a+b) System.out.print System.out System System.out a+b a b public class Main{
    public static Scanner scn=new Scanner (System.in);
    public static void main(String []args){
        ans();
    }
    public static void ans(){
    int x=scn.nextInt();
    int a=(x/500 )*1000;
    int b=(x%500);
   b=b/5;
   b=b*5;
    System.out.print(a+b);

    
    }
} public class Main{
    public static Scanner scn=new Scanner (System.in);
    public static void main(String []args){
        ans();
    }
    public static void ans(){
    int x=scn.nextInt();
    int a=(x/500 )*1000;
    int b=(x%500);
   b=b/5;
   b=b*5;
    System.out.print(a+b);

    
    }
} Main
import java.util.Scanner;
public class Main{
    public static Scanner scn=new Scanner (System.in);
    public static void main(String []args){
        ans();
    }
    public static void ans(){
    int x=scn.nextInt();
    int a=(x/500 )*1000;
    int b=(x%500);
   b=b/5;
   b=b*5;
    System.out.print(a+b);

    
    }
}
  