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