import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int item1 = x / 500;
		int ans = item1 * 1000;
		item1 = (x % 500) / 5;
		ans += item1 * 5;
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int item1 = x / 500;
		int ans = item1 * 1000;
		item1 = (x % 500) / 5;
		ans += item1 * 5;
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int item1 = x / 500;
		int ans = item1 * 1000;
		item1 = (x % 500) / 5;
		ans += item1 * 5;
		System.out.println(ans);
	} main {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int item1 = x / 500;
		int ans = item1 * 1000;
		item1 = (x % 500) / 5;
		ans += item1 * 5;
		System.out.println(ans);
	} Scanner scn = new Scanner(System.in); scn new Scanner(System.in) int x = scn.nextInt(); x scn.nextInt() scn.nextInt scn int item1 = x / 500; item1 x / 500 x 500 int ans = item1 * 1000; ans item1 * 1000 item1 1000 item1 = (x % 500) / 5 item1 (x % 500) / 5 (x % 500) x 500 5 ans += item1 * 5 ans item1 * 5 item1 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) {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int item1 = x / 500;
		int ans = item1 * 1000;
		item1 = (x % 500) / 5;
		ans += item1 * 5;
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int item1 = x / 500;
		int ans = item1 * 1000;
		item1 = (x % 500) / 5;
		ans += item1 * 5;
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int item1 = x / 500;
		int ans = item1 * 1000;
		item1 = (x % 500) / 5;
		ans += item1 * 5;
		System.out.println(ans);
	}
}
