import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int max = 0;

		if(x / 500 > 0){
			max = ((x / 500) * 1000) + max;
			if((x % 500) / 5 > 0){
				max = (((x % 500) / 5) * 5) + max;
			}
		}
		else if(x / 5 > 0){
			max = (x / 5) * 5 + max;
		}

		System.out.println(max);
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int max = 0;

		if(x / 500 > 0){
			max = ((x / 500) * 1000) + max;
			if((x % 500) / 5 > 0){
				max = (((x % 500) / 5) * 5) + max;
			}
		}
		else if(x / 5 > 0){
			max = (x / 5) * 5 + max;
		}

		System.out.println(max);
		sc.close();
	}
} Main public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int max = 0;

		if(x / 500 > 0){
			max = ((x / 500) * 1000) + max;
			if((x % 500) / 5 > 0){
				max = (((x % 500) / 5) * 5) + max;
			}
		}
		else if(x / 5 > 0){
			max = (x / 5) * 5 + max;
		}

		System.out.println(max);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int max = 0;

		if(x / 500 > 0){
			max = ((x / 500) * 1000) + max;
			if((x % 500) / 5 > 0){
				max = (((x % 500) / 5) * 5) + max;
			}
		}
		else if(x / 5 > 0){
			max = (x / 5) * 5 + max;
		}

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

		if(x / 500 > 0){
			max = ((x / 500) * 1000) + max;
			if((x % 500) / 5 > 0){
				max = (((x % 500) / 5) * 5) + max;
			}
		}
		else if(x / 5 > 0){
			max = (x / 5) * 5 + max;
		}

		System.out.println(max);
		sc.close();
	}
} public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int max = 0;

		if(x / 500 > 0){
			max = ((x / 500) * 1000) + max;
			if((x % 500) / 5 > 0){
				max = (((x % 500) / 5) * 5) + max;
			}
		}
		else if(x / 5 > 0){
			max = (x / 5) * 5 + max;
		}

		System.out.println(max);
		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int max = 0;

		if(x / 500 > 0){
			max = ((x / 500) * 1000) + max;
			if((x % 500) / 5 > 0){
				max = (((x % 500) / 5) * 5) + max;
			}
		}
		else if(x / 5 > 0){
			max = (x / 5) * 5 + max;
		}

		System.out.println(max);
		sc.close();
	}
}