import java.util.*;
class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int m = N%500;
        System.out.println(N/500*1000+m/5*5);

    }
} import java.util.*; util.* java class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int m = N%500;
        System.out.println(N/500*1000+m/5*5);

    }
} Main public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int m = N%500;
        System.out.println(N/500*1000+m/5*5);

    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int m = N%500;
        System.out.println(N/500*1000+m/5*5);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int m = N%500; m N%500 N 500 System.out.println(N/500*1000+m/5*5) System.out.println System.out System System.out N/500*1000+m/5*5 N/500*1000 N/500 N 500 1000 m/5*5 m/5 m 5 5 String args[] args
import java.util.*;
class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int m = N%500;
        System.out.println(N/500*1000+m/5*5);

    }
}