import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int a = n / 500;
        n -= 500*a;
        int b = n / 5;
        System.out.println(a*1000 + b*5);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int a = n / 500;
        n -= 500*a;
        int b = n / 5;
        System.out.println(a*1000 + b*5);
    }
} Main public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int a = n / 500;
        n -= 500*a;
        int b = n / 5;
        System.out.println(a*1000 + b*5);
    } main {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int a = n / 500;
        n -= 500*a;
        int b = n / 5;
        System.out.println(a*1000 + b*5);
    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int a = n / 500; a n / 500 n 500 n -= 500*a n 500*a 500 a int b = n / 5; b n / 5 n 5 System.out.println(a*1000 + b*5) System.out.println System.out System System.out a*1000 + b*5 a*1000 a 1000 b*5 b 5 String[] args args public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int a = n / 500;
        n -= 500*a;
        int b = n / 5;
        System.out.println(a*1000 + b*5);
    }
} public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int a = n / 500;
        n -= 500*a;
        int b = n / 5;
        System.out.println(a*1000 + b*5);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int a = n / 500;
        n -= 500*a;
        int b = n / 5;
        System.out.println(a*1000 + b*5);
    }
}
