import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int happy = 0;
        
        while(X>0){
            if(X>=500){
                happy+=1000;
                X-=500;
            }else{
                break;
            }
        }
        
        happy+=(X/5)*5;
        
        System.out.println(happy);
    }
} 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 happy = 0;
        
        while(X>0){
            if(X>=500){
                happy+=1000;
                X-=500;
            }else{
                break;
            }
        }
        
        happy+=(X/5)*5;
        
        System.out.println(happy);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int happy = 0;
        
        while(X>0){
            if(X>=500){
                happy+=1000;
                X-=500;
            }else{
                break;
            }
        }
        
        happy+=(X/5)*5;
        
        System.out.println(happy);
    } main {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int happy = 0;
        
        while(X>0){
            if(X>=500){
                happy+=1000;
                X-=500;
            }else{
                break;
            }
        }
        
        happy+=(X/5)*5;
        
        System.out.println(happy);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int happy = 0; happy 0 while(X>0){
            if(X>=500){
                happy+=1000;
                X-=500;
            }else{
                break;
            }
        } X>0 X 0 {
            if(X>=500){
                happy+=1000;
                X-=500;
            }else{
                break;
            }
        } if(X>=500){
                happy+=1000;
                X-=500;
            }else{
                break;
            } X>=500 X 500 {
                happy+=1000;
                X-=500;
            } happy+=1000 happy 1000 X-=500 X 500 {
                break;
            } break; happy+=(X/5)*5 happy (X/5)*5 (X/5) X 5 5 System.out.println(happy) System.out.println System.out System System.out happy String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int happy = 0;
        
        while(X>0){
            if(X>=500){
                happy+=1000;
                X-=500;
            }else{
                break;
            }
        }
        
        happy+=(X/5)*5;
        
        System.out.println(happy);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int happy = 0;
        
        while(X>0){
            if(X>=500){
                happy+=1000;
                X-=500;
            }else{
                break;
            }
        }
        
        happy+=(X/5)*5;
        
        System.out.println(happy);
    }
} Main
import java.util.*;

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