import java.util.Scanner;

public class Main{
	public static void main(String[] args)throws Exception {
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int yen500 = 0;
		int yen5 = 0;

		for(;;) {
			if(money >= 500) {
				money -= 500;
				yen500 += 1;
			}else {
				break;
			}
		}
		for(;;) {
			if(money >= 5) {
				money -= 5;
				yen5 += 1;
			}else {
				break;
			}
		}
		System.out.println(yen500 * 1000 + yen5 * 5);

		scan.close();
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args)throws Exception {
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int yen500 = 0;
		int yen5 = 0;

		for(;;) {
			if(money >= 500) {
				money -= 500;
				yen500 += 1;
			}else {
				break;
			}
		}
		for(;;) {
			if(money >= 5) {
				money -= 5;
				yen5 += 1;
			}else {
				break;
			}
		}
		System.out.println(yen500 * 1000 + yen5 * 5);

		scan.close();
	}
} Main public static void main(String[] args)throws Exception {
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int yen500 = 0;
		int yen5 = 0;

		for(;;) {
			if(money >= 500) {
				money -= 500;
				yen500 += 1;
			}else {
				break;
			}
		}
		for(;;) {
			if(money >= 5) {
				money -= 5;
				yen5 += 1;
			}else {
				break;
			}
		}
		System.out.println(yen500 * 1000 + yen5 * 5);

		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int yen500 = 0;
		int yen5 = 0;

		for(;;) {
			if(money >= 500) {
				money -= 500;
				yen500 += 1;
			}else {
				break;
			}
		}
		for(;;) {
			if(money >= 5) {
				money -= 5;
				yen5 += 1;
			}else {
				break;
			}
		}
		System.out.println(yen500 * 1000 + yen5 * 5);

		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int money = scan.nextInt(); money scan.nextInt() scan.nextInt scan int yen500 = 0; yen500 0 int yen5 = 0; yen5 0 for(;;) {
			if(money >= 500) {
				money -= 500;
				yen500 += 1;
			}else {
				break;
			}
		} ; {
			if(money >= 500) {
				money -= 500;
				yen500 += 1;
			}else {
				break;
			}
		} {
			if(money >= 500) {
				money -= 500;
				yen500 += 1;
			}else {
				break;
			}
		} if(money >= 500) {
				money -= 500;
				yen500 += 1;
			}else {
				break;
			} money >= 500 money 500 {
				money -= 500;
				yen500 += 1;
			} money -= 500 money 500 yen500 += 1 yen500 1 {
				break;
			} break; for(;;) {
			if(money >= 5) {
				money -= 5;
				yen5 += 1;
			}else {
				break;
			}
		} ; {
			if(money >= 5) {
				money -= 5;
				yen5 += 1;
			}else {
				break;
			}
		} {
			if(money >= 5) {
				money -= 5;
				yen5 += 1;
			}else {
				break;
			}
		} if(money >= 5) {
				money -= 5;
				yen5 += 1;
			}else {
				break;
			} money >= 5 money 5 {
				money -= 5;
				yen5 += 1;
			} money -= 5 money 5 yen5 += 1 yen5 1 {
				break;
			} break; System.out.println(yen500 * 1000 + yen5 * 5) System.out.println System.out System System.out yen500 * 1000 + yen5 * 5 yen500 * 1000 yen500 1000 yen5 * 5 yen5 5 scan.close() scan.close scan String[] args args public class Main{
	public static void main(String[] args)throws Exception {
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int yen500 = 0;
		int yen5 = 0;

		for(;;) {
			if(money >= 500) {
				money -= 500;
				yen500 += 1;
			}else {
				break;
			}
		}
		for(;;) {
			if(money >= 5) {
				money -= 5;
				yen5 += 1;
			}else {
				break;
			}
		}
		System.out.println(yen500 * 1000 + yen5 * 5);

		scan.close();
	}
} public class Main{
	public static void main(String[] args)throws Exception {
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int yen500 = 0;
		int yen5 = 0;

		for(;;) {
			if(money >= 500) {
				money -= 500;
				yen500 += 1;
			}else {
				break;
			}
		}
		for(;;) {
			if(money >= 5) {
				money -= 5;
				yen5 += 1;
			}else {
				break;
			}
		}
		System.out.println(yen500 * 1000 + yen5 * 5);

		scan.close();
	}
} Main
import java.util.Scanner;

public class Main{
	public static void main(String[] args)throws Exception {
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int yen500 = 0;
		int yen5 = 0;

		for(;;) {
			if(money >= 500) {
				money -= 500;
				yen500 += 1;
			}else {
				break;
			}
		}
		for(;;) {
			if(money >= 5) {
				money -= 5;
				yen5 += 1;
			}else {
				break;
			}
		}
		System.out.println(yen500 * 1000 + yen5 * 5);

		scan.close();
	}
}