import java.util.*;

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

        long x = scan.nextLong();
        long u = 0;
        while(x >= 500) {
            x -= 500;
            u += 1000;
        }
        while(x >= 5) {
            x -= 5;
            u += 5;
        }
        System.out.println(u);

        scan.close();
        return;
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        long x = scan.nextLong();
        long u = 0;
        while(x >= 500) {
            x -= 500;
            u += 1000;
        }
        while(x >= 5) {
            x -= 5;
            u += 5;
        }
        System.out.println(u);

        scan.close();
        return;
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        long x = scan.nextLong();
        long u = 0;
        while(x >= 500) {
            x -= 500;
            u += 1000;
        }
        while(x >= 5) {
            x -= 5;
            u += 5;
        }
        System.out.println(u);

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

        long x = scan.nextLong();
        long u = 0;
        while(x >= 500) {
            x -= 500;
            u += 1000;
        }
        while(x >= 5) {
            x -= 5;
            u += 5;
        }
        System.out.println(u);

        scan.close();
        return;
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long x = scan.nextLong(); x scan.nextLong() scan.nextLong scan long u = 0; u 0 while(x >= 500) {
            x -= 500;
            u += 1000;
        } x >= 500 x 500 {
            x -= 500;
            u += 1000;
        } x -= 500 x 500 u += 1000 u 1000 while(x >= 5) {
            x -= 5;
            u += 5;
        } x >= 5 x 5 {
            x -= 5;
            u += 5;
        } x -= 5 x 5 u += 5 u 5 System.out.println(u) System.out.println System.out System System.out u scan.close() scan.close scan return; String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        long x = scan.nextLong();
        long u = 0;
        while(x >= 500) {
            x -= 500;
            u += 1000;
        }
        while(x >= 5) {
            x -= 5;
            u += 5;
        }
        System.out.println(u);

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

        long x = scan.nextLong();
        long u = 0;
        while(x >= 500) {
            x -= 500;
            u += 1000;
        }
        while(x >= 5) {
            x -= 5;
            u += 5;
        }
        System.out.println(u);

        scan.close();
        return;
    }
} Main
import java.util.*;

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

        long x = scan.nextLong();
        long u = 0;
        while(x >= 500) {
            x -= 500;
            u += 1000;
        }
        while(x >= 5) {
            x -= 5;
            u += 5;
        }
        System.out.println(u);

        scan.close();
        return;
    }
}