import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String[] args)throws IOException {
		InputStreamReader read=new InputStreamReader(System.in);
		BufferedReader in=new BufferedReader(read);
		int x=Integer.parseInt(in.readLine());
		long ans=0;
		while(x>=500)
		{
		    ans+=1000;
		    x-=500;
		}
		while(x>=5)
		{
		    ans+=5;
		    x-=5;
		}
		System.out.println(ans);
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main
{
	public static void main(String[] args)throws IOException {
		InputStreamReader read=new InputStreamReader(System.in);
		BufferedReader in=new BufferedReader(read);
		int x=Integer.parseInt(in.readLine());
		long ans=0;
		while(x>=500)
		{
		    ans+=1000;
		    x-=500;
		}
		while(x>=5)
		{
		    ans+=5;
		    x-=5;
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args)throws IOException {
		InputStreamReader read=new InputStreamReader(System.in);
		BufferedReader in=new BufferedReader(read);
		int x=Integer.parseInt(in.readLine());
		long ans=0;
		while(x>=500)
		{
		    ans+=1000;
		    x-=500;
		}
		while(x>=5)
		{
		    ans+=5;
		    x-=5;
		}
		System.out.println(ans);
	} main {
		InputStreamReader read=new InputStreamReader(System.in);
		BufferedReader in=new BufferedReader(read);
		int x=Integer.parseInt(in.readLine());
		long ans=0;
		while(x>=500)
		{
		    ans+=1000;
		    x-=500;
		}
		while(x>=5)
		{
		    ans+=5;
		    x-=5;
		}
		System.out.println(ans);
	} InputStreamReader read=new InputStreamReader(System.in); read new InputStreamReader(System.in) BufferedReader in=new BufferedReader(read); in new BufferedReader(read) int x=Integer.parseInt(in.readLine()); x Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in long ans=0; ans 0 while(x>=500)
		{
		    ans+=1000;
		    x-=500;
		} x>=500 x 500 {
		    ans+=1000;
		    x-=500;
		} ans+=1000 ans 1000 x-=500 x 500 while(x>=5)
		{
		    ans+=5;
		    x-=5;
		} x>=5 x 5 {
		    ans+=5;
		    x-=5;
		} ans+=5 ans 5 x-=5 x 5 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main
{
	public static void main(String[] args)throws IOException {
		InputStreamReader read=new InputStreamReader(System.in);
		BufferedReader in=new BufferedReader(read);
		int x=Integer.parseInt(in.readLine());
		long ans=0;
		while(x>=500)
		{
		    ans+=1000;
		    x-=500;
		}
		while(x>=5)
		{
		    ans+=5;
		    x-=5;
		}
		System.out.println(ans);
	}
} public class Main
{
	public static void main(String[] args)throws IOException {
		InputStreamReader read=new InputStreamReader(System.in);
		BufferedReader in=new BufferedReader(read);
		int x=Integer.parseInt(in.readLine());
		long ans=0;
		while(x>=500)
		{
		    ans+=1000;
		    x-=500;
		}
		while(x>=5)
		{
		    ans+=5;
		    x-=5;
		}
		System.out.println(ans);
	}
} Main
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String[] args)throws IOException {
		InputStreamReader read=new InputStreamReader(System.in);
		BufferedReader in=new BufferedReader(read);
		int x=Integer.parseInt(in.readLine());
		long ans=0;
		while(x>=500)
		{
		    ans+=1000;
		    x-=500;
		}
		while(x>=5)
		{
		    ans+=5;
		    x-=5;
		}
		System.out.println(ans);
	}
}
