import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int X = scan.nextInt();
        int div500 = X/500;
        X = X - 500*div500;
        int div5 = X/5;
        System.out.println(1000*div500+5*div5);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int X = scan.nextInt();
        int div500 = X/500;
        X = X - 500*div500;
        int div5 = X/5;
        System.out.println(1000*div500+5*div5);
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int X = scan.nextInt();
        int div500 = X/500;
        X = X - 500*div500;
        int div5 = X/5;
        System.out.println(1000*div500+5*div5);
    } main {
        Scanner scan = new Scanner(System.in);
        int X = scan.nextInt();
        int div500 = X/500;
        X = X - 500*div500;
        int div5 = X/5;
        System.out.println(1000*div500+5*div5);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int X = scan.nextInt(); X scan.nextInt() scan.nextInt scan int div500 = X/500; div500 X/500 X 500 X = X - 500*div500 X X - 500*div500 X 500*div500 500 div500 int div5 = X/5; div5 X/5 X 5 System.out.println(1000*div500+5*div5) System.out.println System.out System System.out 1000*div500+5*div5 1000*div500 1000 div500 5*div5 5 div5 String[] args args public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int X = scan.nextInt();
        int div500 = X/500;
        X = X - 500*div500;
        int div5 = X/5;
        System.out.println(1000*div500+5*div5);
    }
} public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int X = scan.nextInt();
        int div500 = X/500;
        X = X - 500*div500;
        int div5 = X/5;
        System.out.println(1000*div500+5*div5);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int X = scan.nextInt();
        int div500 = X/500;
        X = X - 500*div500;
        int div5 = X/5;
        System.out.println(1000*div500+5*div5);
    }
}