import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int X = stdIn.nextInt();

        int N_500 = 0;
        int N_5 = 0;

        int happy =0;

        N_500  = X / 500;
        N_5 = (X % 500) / 5;

        happy = 1000 * N_500 + 5 * N_5;

        System.out.print(happy);
        




        


    }

} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int X = stdIn.nextInt();

        int N_500 = 0;
        int N_5 = 0;

        int happy =0;

        N_500  = X / 500;
        N_5 = (X % 500) / 5;

        happy = 1000 * N_500 + 5 * N_5;

        System.out.print(happy);
        




        


    }

} Main public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int X = stdIn.nextInt();

        int N_500 = 0;
        int N_5 = 0;

        int happy =0;

        N_500  = X / 500;
        N_5 = (X % 500) / 5;

        happy = 1000 * N_500 + 5 * N_5;

        System.out.print(happy);
        




        


    } main {
        Scanner stdIn = new Scanner(System.in);
        int X = stdIn.nextInt();

        int N_500 = 0;
        int N_5 = 0;

        int happy =0;

        N_500  = X / 500;
        N_5 = (X % 500) / 5;

        happy = 1000 * N_500 + 5 * N_5;

        System.out.print(happy);
        




        


    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int X = stdIn.nextInt(); X stdIn.nextInt() stdIn.nextInt stdIn int N_500 = 0; N_500 0 int N_5 = 0; N_5 0 int happy =0; happy 0 N_500  = X / 500 N_500 X / 500 X 500 N_5 = (X % 500) / 5 N_5 (X % 500) / 5 (X % 500) X 500 5 happy = 1000 * N_500 + 5 * N_5 happy 1000 * N_500 + 5 * N_5 1000 * N_500 1000 N_500 5 * N_5 5 N_5 System.out.print(happy) System.out.print System.out System System.out happy String[] args args public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int X = stdIn.nextInt();

        int N_500 = 0;
        int N_5 = 0;

        int happy =0;

        N_500  = X / 500;
        N_5 = (X % 500) / 5;

        happy = 1000 * N_500 + 5 * N_5;

        System.out.print(happy);
        




        


    }

} public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int X = stdIn.nextInt();

        int N_500 = 0;
        int N_5 = 0;

        int happy =0;

        N_500  = X / 500;
        N_5 = (X % 500) / 5;

        happy = 1000 * N_500 + 5 * N_5;

        System.out.print(happy);
        




        


    }

} Main
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int X = stdIn.nextInt();

        int N_500 = 0;
        int N_5 = 0;

        int happy =0;

        N_500  = X / 500;
        N_5 = (X % 500) / 5;

        happy = 1000 * N_500 + 5 * N_5;

        System.out.print(happy);
        




        


    }

}