import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int x = Integer.parseInt(br.readLine());
        int count500 = x / 500;
        int count5 = x % 500 / 5;
        
        out.println(1000 * count500 + 5 * count5);
        
        out.close();
        
    }
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int x = Integer.parseInt(br.readLine());
        int count500 = x / 500;
        int count5 = x % 500 / 5;
        
        out.println(1000 * count500 + 5 * count5);
        
        out.close();
        
    }
} Main public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int x = Integer.parseInt(br.readLine());
        int count500 = x / 500;
        int count5 = x % 500 / 5;
        
        out.println(1000 * count500 + 5 * count5);
        
        out.close();
        
    } main {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int x = Integer.parseInt(br.readLine());
        int count500 = x / 500;
        int count5 = x % 500 / 5;
        
        out.println(1000 * count500 + 5 * count5);
        
        out.close();
        
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); out new PrintWriter(new OutputStreamWriter(System.out)) int x = Integer.parseInt(br.readLine()); x Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int count500 = x / 500; count500 x / 500 x 500 int count5 = x % 500 / 5; count5 x % 500 / 5 x % 500 x 500 5 out.println(1000 * count500 + 5 * count5) out.println out 1000 * count500 + 5 * count5 1000 * count500 1000 count500 5 * count5 5 count5 out.close() out.close out String[] args args public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int x = Integer.parseInt(br.readLine());
        int count500 = x / 500;
        int count5 = x % 500 / 5;
        
        out.println(1000 * count500 + 5 * count5);
        
        out.close();
        
    }
} public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int x = Integer.parseInt(br.readLine());
        int count500 = x / 500;
        int count5 = x % 500 / 5;
        
        out.println(1000 * count500 + 5 * count5);
        
        out.close();
        
    }
} Main
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int x = Integer.parseInt(br.readLine());
        int count500 = x / 500;
        int count5 = x % 500 / 5;
        
        out.println(1000 * count500 + 5 * count5);
        
        out.close();
        
    }
}