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 (x >= 500) {
			x -= 500;
			ans += 1000;
		}

		while (x >= 5) {
			x -= 5;
			ans += 5;
		}
		
		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 (x >= 500) {
			x -= 500;
			ans += 1000;
		}

		while (x >= 5) {
			x -= 5;
			ans += 5;
		}
		
		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 (x >= 500) {
			x -= 500;
			ans += 1000;
		}

		while (x >= 5) {
			x -= 5;
			ans += 5;
		}
		
		System.out.println(ans);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int x = Integer.parseInt(br.readLine());

		int ans = 0;
		while (x >= 500) {
			x -= 500;
			ans += 1000;
		}

		while (x >= 5) {
			x -= 5;
			ans += 5;
		}
		
		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 (x >= 500) {
			x -= 500;
			ans += 1000;
		} x >= 500 x 500 {
			x -= 500;
			ans += 1000;
		} x -= 500 x 500 ans += 1000 ans 1000 while (x >= 5) {
			x -= 5;
			ans += 5;
		} x >= 5 x 5 {
			x -= 5;
			ans += 5;
		} x -= 5 x 5 ans += 5 ans 5 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 (x >= 500) {
			x -= 500;
			ans += 1000;
		}

		while (x >= 5) {
			x -= 5;
			ans += 5;
		}
		
		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 (x >= 500) {
			x -= 500;
			ans += 1000;
		}

		while (x >= 5) {
			x -= 5;
			ans += 5;
		}
		
		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 (x >= 500) {
			x -= 500;
			ans += 1000;
		}

		while (x >= 5) {
			x -= 5;
			ans += 5;
		}
		
		System.out.println(ans);
	}
}
