import java.io.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int X = Integer.parseInt (reader.readLine());
        int rem = X % 500;
        System.out.println (X / 500 * 1000 + rem / 5 * 5);
    }
} import java.io.*; io.* java public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int X = Integer.parseInt (reader.readLine());
        int rem = X % 500;
        System.out.println (X / 500 * 1000 + rem / 5 * 5);
    }
} Main public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int X = Integer.parseInt (reader.readLine());
        int rem = X % 500;
        System.out.println (X / 500 * 1000 + rem / 5 * 5);
    } main {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int X = Integer.parseInt (reader.readLine());
        int rem = X % 500;
        System.out.println (X / 500 * 1000 + rem / 5 * 5);
    } BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in)); reader new BufferedReader (new InputStreamReader (System.in)) int X = Integer.parseInt (reader.readLine()); X Integer.parseInt (reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader int rem = X % 500; rem X % 500 X 500 System.out.println (X / 500 * 1000 + rem / 5 * 5) System.out.println System.out System System.out X / 500 * 1000 + rem / 5 * 5 X / 500 * 1000 X / 500 X 500 1000 rem / 5 * 5 rem / 5 rem 5 5 String[] args args public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int X = Integer.parseInt (reader.readLine());
        int rem = X % 500;
        System.out.println (X / 500 * 1000 + rem / 5 * 5);
    }
} public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int X = Integer.parseInt (reader.readLine());
        int rem = X % 500;
        System.out.println (X / 500 * 1000 + rem / 5 * 5);
    }
} Main
import java.io.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int X = Integer.parseInt (reader.readLine());
        int rem = X % 500;
        System.out.println (X / 500 * 1000 + rem / 5 * 5);
    }
}