import java.util.*;
class Main
{
	public static void main(String[] args)                                        
	{
		Scanner sc=new Scanner(System.in);
		int t,k,l;
		String p;
		t=sc.nextInt();
		
		l=t/500;
		int a=t%500;
				int ans=l*1000+((a/5)*5);
				System.out.println(ans);

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

		
		
		
		
		
	
		
	}
	
	
			
	
		
} Main public static void main(String[] args)                                        
	{
		Scanner sc=new Scanner(System.in);
		int t,k,l;
		String p;
		t=sc.nextInt();
		
		l=t/500;
		int a=t%500;
				int ans=l*1000+((a/5)*5);
				System.out.println(ans);

		
		
		
		
		
	
		
	} main {
		Scanner sc=new Scanner(System.in);
		int t,k,l;
		String p;
		t=sc.nextInt();
		
		l=t/500;
		int a=t%500;
				int ans=l*1000+((a/5)*5);
				System.out.println(ans);

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

		
		
		
		
		
	
		
	}
	
	
			
	
		
}

