import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();

        System.out.println(solve(X));

        sc.close();
    }

    static int solve(int X) {
        return X / 500 * 1000 + X % 500 / 5 * 5;
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();

        System.out.println(solve(X));

        sc.close();
    }

    static int solve(int X) {
        return X / 500 * 1000 + X % 500 / 5 * 5;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();

        System.out.println(solve(X));

        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();

        System.out.println(solve(X));

        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc System.out.println(solve(X)) System.out.println System.out System System.out solve(X) solve X sc.close() sc.close sc String[] args args static int solve(int X) {
        return X / 500 * 1000 + X % 500 / 5 * 5;
    } solve {
        return X / 500 * 1000 + X % 500 / 5 * 5;
    } return X / 500 * 1000 + X % 500 / 5 * 5; X / 500 * 1000 + X % 500 / 5 * 5 X / 500 * 1000 X / 500 X 500 1000 X % 500 / 5 * 5 X % 500 / 5 X % 500 X 500 5 5 int X X public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();

        System.out.println(solve(X));

        sc.close();
    }

    static int solve(int X) {
        return X / 500 * 1000 + X % 500 / 5 * 5;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();

        System.out.println(solve(X));

        sc.close();
    }

    static int solve(int X) {
        return X / 500 * 1000 + X % 500 / 5 * 5;
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();

        System.out.println(solve(X));

        sc.close();
    }

    static int solve(int X) {
        return X / 500 * 1000 + X % 500 / 5 * 5;
    }
}