import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		int x=s.nextInt();
		int cnt=0;
		
		if(x>=500)
		{
			cnt+=1000*(x/500);
			x%=500;
		}
		if(x>=5)
		{
			cnt+=5*(x/5);
			x%=5;
		}
		
		System.out.println(cnt);
		s.close();
	}
} import java.util.*; util.* java public class Main
{
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		int x=s.nextInt();
		int cnt=0;
		
		if(x>=500)
		{
			cnt+=1000*(x/500);
			x%=500;
		}
		if(x>=5)
		{
			cnt+=5*(x/5);
			x%=5;
		}
		
		System.out.println(cnt);
		s.close();
	}
} Main public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		int x=s.nextInt();
		int cnt=0;
		
		if(x>=500)
		{
			cnt+=1000*(x/500);
			x%=500;
		}
		if(x>=5)
		{
			cnt+=5*(x/5);
			x%=5;
		}
		
		System.out.println(cnt);
		s.close();
	} main {
		Scanner s=new Scanner(System.in);
		int x=s.nextInt();
		int cnt=0;
		
		if(x>=500)
		{
			cnt+=1000*(x/500);
			x%=500;
		}
		if(x>=5)
		{
			cnt+=5*(x/5);
			x%=5;
		}
		
		System.out.println(cnt);
		s.close();
	} Scanner s=new Scanner(System.in); s new Scanner(System.in) int x=s.nextInt(); x s.nextInt() s.nextInt s int cnt=0; cnt 0 if(x>=500)
		{
			cnt+=1000*(x/500);
			x%=500;
		} x>=500 x 500 {
			cnt+=1000*(x/500);
			x%=500;
		} cnt+=1000*(x/500) cnt 1000*(x/500) 1000 (x/500) x 500 x%=500 x 500 if(x>=5)
		{
			cnt+=5*(x/5);
			x%=5;
		} x>=5 x 5 {
			cnt+=5*(x/5);
			x%=5;
		} cnt+=5*(x/5) cnt 5*(x/5) 5 (x/5) x 5 x%=5 x 5 System.out.println(cnt) System.out.println System.out System System.out cnt s.close() s.close s String[] args args public class Main
{
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		int x=s.nextInt();
		int cnt=0;
		
		if(x>=500)
		{
			cnt+=1000*(x/500);
			x%=500;
		}
		if(x>=5)
		{
			cnt+=5*(x/5);
			x%=5;
		}
		
		System.out.println(cnt);
		s.close();
	}
} public class Main
{
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		int x=s.nextInt();
		int cnt=0;
		
		if(x>=500)
		{
			cnt+=1000*(x/500);
			x%=500;
		}
		if(x>=5)
		{
			cnt+=5*(x/5);
			x%=5;
		}
		
		System.out.println(cnt);
		s.close();
	}
} Main
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		int x=s.nextInt();
		int cnt=0;
		
		if(x>=500)
		{
			cnt+=1000*(x/500);
			x%=500;
		}
		if(x>=5)
		{
			cnt+=5*(x/5);
			x%=5;
		}
		
		System.out.println(cnt);
		s.close();
	}
}
