import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int hp=0;
        while(x>=500){
            x-=500;
            hp+=1000;
        }
        while(x>=5){
            x-=5;
            hp+=5;
        }
        System.out.println(hp);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int hp=0;
        while(x>=500){
            x-=500;
            hp+=1000;
        }
        while(x>=5){
            x-=5;
            hp+=5;
        }
        System.out.println(hp);
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int hp=0;
        while(x>=500){
            x-=500;
            hp+=1000;
        }
        while(x>=5){
            x-=5;
            hp+=5;
        }
        System.out.println(hp);
    } main {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int hp=0;
        while(x>=500){
            x-=500;
            hp+=1000;
        }
        while(x>=5){
            x-=5;
            hp+=5;
        }
        System.out.println(hp);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int x = in.nextInt(); x in.nextInt() in.nextInt in int hp=0; hp 0 while(x>=500){
            x-=500;
            hp+=1000;
        } x>=500 x 500 {
            x-=500;
            hp+=1000;
        } x-=500 x 500 hp+=1000 hp 1000 while(x>=5){
            x-=5;
            hp+=5;
        } x>=5 x 5 {
            x-=5;
            hp+=5;
        } x-=5 x 5 hp+=5 hp 5 System.out.println(hp) System.out.println System.out System System.out hp String[] args args public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int hp=0;
        while(x>=500){
            x-=500;
            hp+=1000;
        }
        while(x>=5){
            x-=5;
            hp+=5;
        }
        System.out.println(hp);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int hp=0;
        while(x>=500){
            x-=500;
            hp+=1000;
        }
        while(x>=5){
            x-=5;
            hp+=5;
        }
        System.out.println(hp);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int hp=0;
        while(x>=500){
            x-=500;
            hp+=1000;
        }
        while(x>=5){
            x-=5;
            hp+=5;
        }
        System.out.println(hp);
    }
}
