import java.util.*;
class Main
{
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        long x=sc.nextLong();
        long ans=0;
        while(x>4) {
            if (x / 500 > 0) {
                ans += 1000;
                x -= 500;
                continue;
            }
            if (x / 5> 0) {
                ans += 5;
                x -= 5;
                continue;
            }
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java class Main
{
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        long x=sc.nextLong();
        long ans=0;
        while(x>4) {
            if (x / 500 > 0) {
                ans += 1000;
                x -= 500;
                continue;
            }
            if (x / 5> 0) {
                ans += 5;
                x -= 5;
                continue;
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        long x=sc.nextLong();
        long ans=0;
        while(x>4) {
            if (x / 500 > 0) {
                ans += 1000;
                x -= 500;
                continue;
            }
            if (x / 5> 0) {
                ans += 5;
                x -= 5;
                continue;
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc=new Scanner(System.in);
        long x=sc.nextLong();
        long ans=0;
        while(x>4) {
            if (x / 500 > 0) {
                ans += 1000;
                x -= 500;
                continue;
            }
            if (x / 5> 0) {
                ans += 5;
                x -= 5;
                continue;
            }
        }
        System.out.println(ans);
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) long x=sc.nextLong(); x sc.nextLong() sc.nextLong sc long ans=0; ans 0 while(x>4) {
            if (x / 500 > 0) {
                ans += 1000;
                x -= 500;
                continue;
            }
            if (x / 5> 0) {
                ans += 5;
                x -= 5;
                continue;
            }
        } x>4 x 4 {
            if (x / 500 > 0) {
                ans += 1000;
                x -= 500;
                continue;
            }
            if (x / 5> 0) {
                ans += 5;
                x -= 5;
                continue;
            }
        } if (x / 500 > 0) {
                ans += 1000;
                x -= 500;
                continue;
            } x / 500 > 0 x / 500 x 500 0 {
                ans += 1000;
                x -= 500;
                continue;
            } ans += 1000 ans 1000 x -= 500 x 500 continue; if (x / 5> 0) {
                ans += 5;
                x -= 5;
                continue;
            } x / 5> 0 x / 5 x 5 0 {
                ans += 5;
                x -= 5;
                continue;
            } ans += 5 ans 5 x -= 5 x 5 continue; System.out.println(ans) System.out.println System.out System System.out ans String args[] args
import java.util.*;
class Main
{
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        long x=sc.nextLong();
        long ans=0;
        while(x>4) {
            if (x / 500 > 0) {
                ans += 1000;
                x -= 500;
                continue;
            }
            if (x / 5> 0) {
                ans += 5;
                x -= 5;
                continue;
            }
        }
        System.out.println(ans);
    }
}