import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int rem=n;
        int hap=0;
        int ans=0;
        if (n>=500){
            hap=n/500;
            ans=hap*1000;
            n=n-((n/500)*500);
        }
        if (n>=5){
            hap=n/5;
            ans=ans+hap*5;
        }
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int rem=n;
        int hap=0;
        int ans=0;
        if (n>=500){
            hap=n/500;
            ans=hap*1000;
            n=n-((n/500)*500);
        }
        if (n>=5){
            hap=n/5;
            ans=ans+hap*5;
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int rem=n;
        int hap=0;
        int ans=0;
        if (n>=500){
            hap=n/500;
            ans=hap*1000;
            n=n-((n/500)*500);
        }
        if (n>=5){
            hap=n/5;
            ans=ans+hap*5;
        }
        System.out.println(ans);
    } main {

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int rem=n;
        int hap=0;
        int ans=0;
        if (n>=500){
            hap=n/500;
            ans=hap*1000;
            n=n-((n/500)*500);
        }
        if (n>=5){
            hap=n/5;
            ans=ans+hap*5;
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int rem=n; rem n int hap=0; hap 0 int ans=0; ans 0 if (n>=500){
            hap=n/500;
            ans=hap*1000;
            n=n-((n/500)*500);
        } n>=500 n 500 {
            hap=n/500;
            ans=hap*1000;
            n=n-((n/500)*500);
        } hap=n/500 hap n/500 n 500 ans=hap*1000 ans hap*1000 hap 1000 n=n-((n/500)*500) n n-((n/500)*500) n ((n/500)*500) (n/500) n 500 500 if (n>=5){
            hap=n/5;
            ans=ans+hap*5;
        } n>=5 n 5 {
            hap=n/5;
            ans=ans+hap*5;
        } hap=n/5 hap n/5 n 5 ans=ans+hap*5 ans ans+hap*5 ans hap*5 hap 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) {

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int rem=n;
        int hap=0;
        int ans=0;
        if (n>=500){
            hap=n/500;
            ans=hap*1000;
            n=n-((n/500)*500);
        }
        if (n>=5){
            hap=n/5;
            ans=ans+hap*5;
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int rem=n;
        int hap=0;
        int ans=0;
        if (n>=500){
            hap=n/500;
            ans=hap*1000;
            n=n-((n/500)*500);
        }
        if (n>=5){
            hap=n/5;
            ans=ans+hap*5;
        }
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int rem=n;
        int hap=0;
        int ans=0;
        if (n>=500){
            hap=n/500;
            ans=hap*1000;
            n=n-((n/500)*500);
        }
        if (n>=5){
            hap=n/5;
            ans=ans+hap*5;
        }
        System.out.println(ans);
    }
}
