import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long ans = 0;
        ans += ((long) n / 500) * 1000;
        n %= 500;
        ans += (n / 5) * 5;
        System.out.println(ans);
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long ans = 0;
        ans += ((long) n / 500) * 1000;
        n %= 500;
        ans += (n / 5) * 5;
        System.out.println(ans);
    }

} Main public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long ans = 0;
        ans += ((long) n / 500) * 1000;
        n %= 500;
        ans += (n / 5) * 5;
        System.out.println(ans);
    } main {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long ans = 0;
        ans += ((long) n / 500) * 1000;
        n %= 500;
        ans += (n / 5) * 5;
        System.out.println(ans);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in long ans = 0; ans 0 ans += ((long) n / 500) * 1000 ans ((long) n / 500) * 1000 ((long) n / 500) (long) n 500 1000 n %= 500 n 500 ans += (n / 5) * 5 ans (n / 5) * 5 (n / 5) n 5 5 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long ans = 0;
        ans += ((long) n / 500) * 1000;
        n %= 500;
        ans += (n / 5) * 5;
        System.out.println(ans);
    }

} public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long ans = 0;
        ans += ((long) n / 500) * 1000;
        n %= 500;
        ans += (n / 5) * 5;
        System.out.println(ans);
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long ans = 0;
        ans += ((long) n / 500) * 1000;
        n %= 500;
        ans += (n / 5) * 5;
        System.out.println(ans);
    }

}
