import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int X = Integer.parseInt(br.readLine());
		
		int ans = 0;
		while(true) {
			if(X >= 500) {
				ans += X / 500 * 1000;
				X %= 500;
			} else {
				ans += X / 5 * 5;
				X %= 5;
			}
			
			if(X < 5)
				break;
		}
			
		System.out.println(ans);
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int X = Integer.parseInt(br.readLine());
		
		int ans = 0;
		while(true) {
			if(X >= 500) {
				ans += X / 500 * 1000;
				X %= 500;
			} else {
				ans += X / 5 * 5;
				X %= 5;
			}
			
			if(X < 5)
				break;
		}
			
		System.out.println(ans);
	}

} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int X = Integer.parseInt(br.readLine());
		
		int ans = 0;
		while(true) {
			if(X >= 500) {
				ans += X / 500 * 1000;
				X %= 500;
			} else {
				ans += X / 5 * 5;
				X %= 5;
			}
			
			if(X < 5)
				break;
		}
			
		System.out.println(ans);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int X = Integer.parseInt(br.readLine());
		
		int ans = 0;
		while(true) {
			if(X >= 500) {
				ans += X / 500 * 1000;
				X %= 500;
			} else {
				ans += X / 5 * 5;
				X %= 5;
			}
			
			if(X < 5)
				break;
		}
			
		System.out.println(ans);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int X = Integer.parseInt(br.readLine()); X Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int ans = 0; ans 0 while(true) {
			if(X >= 500) {
				ans += X / 500 * 1000;
				X %= 500;
			} else {
				ans += X / 5 * 5;
				X %= 5;
			}
			
			if(X < 5)
				break;
		} true {
			if(X >= 500) {
				ans += X / 500 * 1000;
				X %= 500;
			} else {
				ans += X / 5 * 5;
				X %= 5;
			}
			
			if(X < 5)
				break;
		} if(X >= 500) {
				ans += X / 500 * 1000;
				X %= 500;
			} else {
				ans += X / 5 * 5;
				X %= 5;
			} X >= 500 X 500 {
				ans += X / 500 * 1000;
				X %= 500;
			} ans += X / 500 * 1000 ans X / 500 * 1000 X / 500 X 500 1000 X %= 500 X 500 {
				ans += X / 5 * 5;
				X %= 5;
			} ans += X / 5 * 5 ans X / 5 * 5 X / 5 X 5 5 X %= 5 X 5 if(X < 5)
				break; X < 5 X 5 break; 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 {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int X = Integer.parseInt(br.readLine());
		
		int ans = 0;
		while(true) {
			if(X >= 500) {
				ans += X / 500 * 1000;
				X %= 500;
			} else {
				ans += X / 5 * 5;
				X %= 5;
			}
			
			if(X < 5)
				break;
		}
			
		System.out.println(ans);
	}

} public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int X = Integer.parseInt(br.readLine());
		
		int ans = 0;
		while(true) {
			if(X >= 500) {
				ans += X / 500 * 1000;
				X %= 500;
			} else {
				ans += X / 5 * 5;
				X %= 5;
			}
			
			if(X < 5)
				break;
		}
			
		System.out.println(ans);
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int X = Integer.parseInt(br.readLine());
		
		int ans = 0;
		while(true) {
			if(X >= 500) {
				ans += X / 500 * 1000;
				X %= 500;
			} else {
				ans += X / 5 * 5;
				X %= 5;
			}
			
			if(X < 5)
				break;
		}
			
		System.out.println(ans);
	}

}