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

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long X;
        X = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(X);
    }
}

class Solver {
    public void solve(long X) {
        long ans = 0;
        ans += X / 500 * 1000;
        X %= 500;
        ans += X / 5 * 5;
        System.out.println(ans);
    }
}
 import java.io.*; io.* java import java.util.*; util.* java public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long X;
        X = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(X);
    }
} Main public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long X;
        X = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(X);
    } main {
        final Scanner sc = new Scanner(System.in);
        long X;
        X = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(X);
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long X; X X = sc.nextLong() X sc.nextLong() sc.nextLong sc final Solver solver = new Solver(); solver new Solver() solver.solve(X) solver.solve solver X final String[] args args class Solver {
    public void solve(long X) {
        long ans = 0;
        ans += X / 500 * 1000;
        X %= 500;
        ans += X / 5 * 5;
        System.out.println(ans);
    }
} Solver public void solve(long X) {
        long ans = 0;
        ans += X / 500 * 1000;
        X %= 500;
        ans += X / 5 * 5;
        System.out.println(ans);
    } solve {
        long ans = 0;
        ans += X / 500 * 1000;
        X %= 500;
        ans += X / 5 * 5;
        System.out.println(ans);
    } long ans = 0; ans 0 ans += X / 500 * 1000 ans X / 500 * 1000 X / 500 X 500 1000 X %= 500 X 500 ans += X / 5 * 5 ans X / 5 * 5 X / 5 X 5 5 System.out.println(ans) System.out.println System.out System System.out ans long X X public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long X;
        X = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(X);
    }
} public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long X;
        X = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(X);
    }
} Main
import java.io.*;
import java.util.*;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long X;
        X = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(X);
    }
}

class Solver {
    public void solve(long X) {
        long ans = 0;
        ans += X / 500 * 1000;
        X %= 500;
        ans += X / 5 * 5;
        System.out.println(ans);
    }
}

