import java.util.*;

class Main {
    private static Scanner sc;

    public static void main(final String[] args) {
        sc = new Scanner(System.in);
        long a = sc.nextLong(),b = 0;
        if(a >= 500) {
            b = (a / 500) * 1000;
            a %= 500;
        }
        if(a >= 5) b += (a / 5) * 5;
        System.out.println(b);
    }
}





 import java.util.*; util.* java class Main {
    private static Scanner sc;

    public static void main(final String[] args) {
        sc = new Scanner(System.in);
        long a = sc.nextLong(),b = 0;
        if(a >= 500) {
            b = (a / 500) * 1000;
            a %= 500;
        }
        if(a >= 5) b += (a / 5) * 5;
        System.out.println(b);
    }
} Main private static Scanner sc; sc public static void main(final String[] args) {
        sc = new Scanner(System.in);
        long a = sc.nextLong(),b = 0;
        if(a >= 500) {
            b = (a / 500) * 1000;
            a %= 500;
        }
        if(a >= 5) b += (a / 5) * 5;
        System.out.println(b);
    } main {
        sc = new Scanner(System.in);
        long a = sc.nextLong(),b = 0;
        if(a >= 500) {
            b = (a / 500) * 1000;
            a %= 500;
        }
        if(a >= 5) b += (a / 5) * 5;
        System.out.println(b);
    } sc = new Scanner(System.in) sc new Scanner(System.in) long a = sc.nextLong() a sc.nextLong() sc.nextLong sc b = 0; b 0 if(a >= 500) {
            b = (a / 500) * 1000;
            a %= 500;
        } a >= 500 a 500 {
            b = (a / 500) * 1000;
            a %= 500;
        } b = (a / 500) * 1000 b (a / 500) * 1000 (a / 500) a 500 1000 a %= 500 a 500 if(a >= 5) b += (a / 5) * 5; a >= 5 a 5 b += (a / 5) * 5 b (a / 5) * 5 (a / 5) a 5 5 System.out.println(b) System.out.println System.out System System.out b final String[] args args
import java.util.*;

class Main {
    private static Scanner sc;

    public static void main(final String[] args) {
        sc = new Scanner(System.in);
        long a = sc.nextLong(),b = 0;
        if(a >= 500) {
            b = (a / 500) * 1000;
            a %= 500;
        }
        if(a >= 5) b += (a / 5) * 5;
        System.out.println(b);
    }
}






