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