import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int x = sc.nextInt();
		println(x / 500 * 1000 + x % 500 / 5 * 5);
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int x = sc.nextInt();
		println(x / 500 * 1000 + x % 500 / 5 * 5);
	}
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Main() { super(System.out, true); } Main { super(System.out, true); } super(System.out, true) super System.out System System.out true public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	} main {
		Main o = new Main(); o.main(); o.flush();
	} Main o = new Main(); o new Main() o.main() o.main o o.flush() o.flush o String[] $ $ void main() {
		int x = sc.nextInt();
		println(x / 500 * 1000 + x % 500 / 5 * 5);
	} main {
		int x = sc.nextInt();
		println(x / 500 * 1000 + x % 500 / 5 * 5);
	} int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc println(x / 500 * 1000 + x % 500 / 5 * 5) println x / 500 * 1000 + x % 500 / 5 * 5 x / 500 * 1000 x / 500 x 500 1000 x % 500 / 5 * 5 x % 500 / 5 x % 500 x 500 5 5 PrintWriter public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int x = sc.nextInt();
		println(x / 500 * 1000 + x % 500 / 5 * 5);
	}
} public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int x = sc.nextInt();
		println(x / 500 * 1000 + x % 500 / 5 * 5);
	}
} Main
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int x = sc.nextInt();
		println(x / 500 * 1000 + x % 500 / 5 * 5);
	}
}
