import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int x = sc.nextInt();
		long count = 0;
		while(true) {
			if(x>=500) {
				x=x-500;
				count=count+1000;
			}
			else if(x>=5) {
				x=x-5;
				count=count+5;
			}
			else {
				break;
			}
		}
		System.out.println(count);

	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int x = sc.nextInt();
		long count = 0;
		while(true) {
			if(x>=500) {
				x=x-500;
				count=count+1000;
			}
			else if(x>=5) {
				x=x-5;
				count=count+5;
			}
			else {
				break;
			}
		}
		System.out.println(count);

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int x = sc.nextInt();
		long count = 0;
		while(true) {
			if(x>=500) {
				x=x-500;
				count=count+1000;
			}
			else if(x>=5) {
				x=x-5;
				count=count+5;
			}
			else {
				break;
			}
		}
		System.out.println(count);

	} main {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int x = sc.nextInt();
		long count = 0;
		while(true) {
			if(x>=500) {
				x=x-500;
				count=count+1000;
			}
			else if(x>=5) {
				x=x-5;
				count=count+5;
			}
			else {
				break;
			}
		}
		System.out.println(count);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc long count = 0; count 0 while(true) {
			if(x>=500) {
				x=x-500;
				count=count+1000;
			}
			else if(x>=5) {
				x=x-5;
				count=count+5;
			}
			else {
				break;
			}
		} true {
			if(x>=500) {
				x=x-500;
				count=count+1000;
			}
			else if(x>=5) {
				x=x-5;
				count=count+5;
			}
			else {
				break;
			}
		} if(x>=500) {
				x=x-500;
				count=count+1000;
			}
			else if(x>=5) {
				x=x-5;
				count=count+5;
			}
			else {
				break;
			} x>=500 x 500 {
				x=x-500;
				count=count+1000;
			} x=x-500 x x-500 x 500 count=count+1000 count count+1000 count 1000 if(x>=5) {
				x=x-5;
				count=count+5;
			}
			else {
				break;
			} x>=5 x 5 {
				x=x-5;
				count=count+5;
			} x=x-5 x x-5 x 5 count=count+5 count count+5 count 5 {
				break;
			} break; System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int x = sc.nextInt();
		long count = 0;
		while(true) {
			if(x>=500) {
				x=x-500;
				count=count+1000;
			}
			else if(x>=5) {
				x=x-5;
				count=count+5;
			}
			else {
				break;
			}
		}
		System.out.println(count);

	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int x = sc.nextInt();
		long count = 0;
		while(true) {
			if(x>=500) {
				x=x-500;
				count=count+1000;
			}
			else if(x>=5) {
				x=x-5;
				count=count+5;
			}
			else {
				break;
			}
		}
		System.out.println(count);

	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int x = sc.nextInt();
		long count = 0;
		while(true) {
			if(x>=500) {
				x=x-500;
				count=count+1000;
			}
			else if(x>=5) {
				x=x-5;
				count=count+5;
			}
			else {
				break;
			}
		}
		System.out.println(count);

	}
}