import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
 
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int point = 0;
		while (money >= 500) {
			money -= 500;
			point += 1000;
		}
		while (money >= 5) {
			money -= 5;
			point += 5;
		}
		System.out.println(point);
		scan.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
 
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int point = 0;
		while (money >= 500) {
			money -= 500;
			point += 1000;
		}
		while (money >= 5) {
			money -= 5;
			point += 5;
		}
		System.out.println(point);
		scan.close();
	}
} Main public static void main(String[] args) {
 
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int point = 0;
		while (money >= 500) {
			money -= 500;
			point += 1000;
		}
		while (money >= 5) {
			money -= 5;
			point += 5;
		}
		System.out.println(point);
		scan.close();
	} main {
 
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int point = 0;
		while (money >= 500) {
			money -= 500;
			point += 1000;
		}
		while (money >= 5) {
			money -= 5;
			point += 5;
		}
		System.out.println(point);
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int money = scan.nextInt(); money scan.nextInt() scan.nextInt scan int point = 0; point 0 while (money >= 500) {
			money -= 500;
			point += 1000;
		} money >= 500 money 500 {
			money -= 500;
			point += 1000;
		} money -= 500 money 500 point += 1000 point 1000 while (money >= 5) {
			money -= 5;
			point += 5;
		} money >= 5 money 5 {
			money -= 5;
			point += 5;
		} money -= 5 money 5 point += 5 point 5 System.out.println(point) System.out.println System.out System System.out point scan.close() scan.close scan String[] args args public class Main {
	public static void main(String[] args) {
 
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int point = 0;
		while (money >= 500) {
			money -= 500;
			point += 1000;
		}
		while (money >= 5) {
			money -= 5;
			point += 5;
		}
		System.out.println(point);
		scan.close();
	}
} public class Main {
	public static void main(String[] args) {
 
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int point = 0;
		while (money >= 500) {
			money -= 500;
			point += 1000;
		}
		while (money >= 5) {
			money -= 5;
			point += 5;
		}
		System.out.println(point);
		scan.close();
	}
} Main
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
 
		Scanner scan = new Scanner(System.in);
		int money = scan.nextInt();
		int point = 0;
		while (money >= 500) {
			money -= 500;
			point += 1000;
		}
		while (money >= 5) {
			money -= 5;
			point += 5;
		}
		System.out.println(point);
		scan.close();
	}
}