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

public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int happiness = 0;
        while (n >= 500) {
            happiness+=1000;
            n-=500;
        }
        while (n >= 5) {
            happiness+=5;
            n-=5;
        }
        System.out.println(happiness);
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        bw.write("\n");
//        bw.close();
    }

} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int happiness = 0;
        while (n >= 500) {
            happiness+=1000;
            n-=500;
        }
        while (n >= 5) {
            happiness+=5;
            n-=5;
        }
        System.out.println(happiness);
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        bw.write("\n");
//        bw.close();
    }

} Main public static void main(String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int happiness = 0;
        while (n >= 500) {
            happiness+=1000;
            n-=500;
        }
        while (n >= 5) {
            happiness+=5;
            n-=5;
        }
        System.out.println(happiness);
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        bw.write("\n");
//        bw.close();
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int happiness = 0;
        while (n >= 500) {
            happiness+=1000;
            n-=500;
        }
        while (n >= 5) {
            happiness+=5;
            n-=5;
        }
        System.out.println(happiness);
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        bw.write("\n");
//        bw.close();
    } BufferedReader br = new BufferedReader(new InputStreamReader((System.in))); br new BufferedReader(new InputStreamReader((System.in))) StringTokenizer st = new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) int n = Integer.parseInt(st.nextToken()); n Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int happiness = 0; happiness 0 while (n >= 500) {
            happiness+=1000;
            n-=500;
        } n >= 500 n 500 {
            happiness+=1000;
            n-=500;
        } happiness+=1000 happiness 1000 n-=500 n 500 while (n >= 5) {
            happiness+=5;
            n-=5;
        } n >= 5 n 5 {
            happiness+=5;
            n-=5;
        } happiness+=5 happiness 5 n-=5 n 5 System.out.println(happiness) System.out.println System.out System System.out happiness String[] args args public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int happiness = 0;
        while (n >= 500) {
            happiness+=1000;
            n-=500;
        }
        while (n >= 5) {
            happiness+=5;
            n-=5;
        }
        System.out.println(happiness);
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        bw.write("\n");
//        bw.close();
    }

} public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int happiness = 0;
        while (n >= 500) {
            happiness+=1000;
            n-=500;
        }
        while (n >= 5) {
            happiness+=5;
            n-=5;
        }
        System.out.println(happiness);
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        bw.write("\n");
//        bw.close();
    }

} Main
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int happiness = 0;
        while (n >= 500) {
            happiness+=1000;
            n-=500;
        }
        while (n >= 5) {
            happiness+=5;
            n-=5;
        }
        System.out.println(happiness);
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        bw.write("\n");
//        bw.close();
    }

}