import java.util.*;
 
public class Main {
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int X = s.nextInt();
        int fiveHundred = X/500;
        X -= fiveHundred*500;
        int five = X/5;
        System.out.println(fiveHundred*1000+five*5);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int X = s.nextInt();
        int fiveHundred = X/500;
        X -= fiveHundred*500;
        int five = X/5;
        System.out.println(fiveHundred*1000+five*5);
    }
} Main public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int X = s.nextInt();
        int fiveHundred = X/500;
        X -= fiveHundred*500;
        int five = X/5;
        System.out.println(fiveHundred*1000+five*5);
    } main {
        Scanner s = new Scanner(System.in);
        int X = s.nextInt();
        int fiveHundred = X/500;
        X -= fiveHundred*500;
        int five = X/5;
        System.out.println(fiveHundred*1000+five*5);
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int X = s.nextInt(); X s.nextInt() s.nextInt s int fiveHundred = X/500; fiveHundred X/500 X 500 X -= fiveHundred*500 X fiveHundred*500 fiveHundred 500 int five = X/5; five X/5 X 5 System.out.println(fiveHundred*1000+five*5) System.out.println System.out System System.out fiveHundred*1000+five*5 fiveHundred*1000 fiveHundred 1000 five*5 five 5 String[] args args public class Main {
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int X = s.nextInt();
        int fiveHundred = X/500;
        X -= fiveHundred*500;
        int five = X/5;
        System.out.println(fiveHundred*1000+five*5);
    }
} public class Main {
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int X = s.nextInt();
        int fiveHundred = X/500;
        X -= fiveHundred*500;
        int five = X/5;
        System.out.println(fiveHundred*1000+five*5);
    }
} Main
import java.util.*;
 
public class Main {
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int X = s.nextInt();
        int fiveHundred = X/500;
        X -= fiveHundred*500;
        int five = X/5;
        System.out.println(fiveHundred*1000+five*5);
    }
}