import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		long K = Long.parseLong(in.readLine());
		long result = K / 500 * 1000;
		K = K % 500;
		result += K /  5 * 5;
		System.out.println(result);
	}

	void calc() {
	}

	void showResult() {
	}

} import java.util.*; util.* java import java.util.stream.Collectors; Collectors java.util.stream import java.io.*; io.* java import java.math.BigDecimal; BigDecimal java.math import java.nio.charset.StandardCharsets; StandardCharsets java.nio.charset public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		long K = Long.parseLong(in.readLine());
		long result = K / 500 * 1000;
		K = K % 500;
		result += K /  5 * 5;
		System.out.println(result);
	}

	void calc() {
	}

	void showResult() {
	}

} Main public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	} main {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	} InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8); reader new InputStreamReader(System.in, StandardCharsets.UTF_8) BufferedReader in = new BufferedReader(reader); in new BufferedReader(reader) Main ins = new Main(in); ins new Main(in) ins.calc() ins.calc ins ins.showResult() ins.showResult ins String[] args args Main(BufferedReader in) throws IOException {
		long K = Long.parseLong(in.readLine());
		long result = K / 500 * 1000;
		K = K % 500;
		result += K /  5 * 5;
		System.out.println(result);
	} Main {
		long K = Long.parseLong(in.readLine());
		long result = K / 500 * 1000;
		K = K % 500;
		result += K /  5 * 5;
		System.out.println(result);
	} long K = Long.parseLong(in.readLine()); K Long.parseLong(in.readLine()) Long.parseLong Long in.readLine() in.readLine in long result = K / 500 * 1000; result K / 500 * 1000 K / 500 K 500 1000 K = K % 500 K K % 500 K 500 result += K /  5 * 5 result K /  5 * 5 K /  5 K 5 5 System.out.println(result) System.out.println System.out System System.out result BufferedReader in in void calc() {
	} calc {
	} void showResult() {
	} showResult {
	} public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		long K = Long.parseLong(in.readLine());
		long result = K / 500 * 1000;
		K = K % 500;
		result += K /  5 * 5;
		System.out.println(result);
	}

	void calc() {
	}

	void showResult() {
	}

} public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		long K = Long.parseLong(in.readLine());
		long result = K / 500 * 1000;
		K = K % 500;
		result += K /  5 * 5;
		System.out.println(result);
	}

	void calc() {
	}

	void showResult() {
	}

} Main
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		long K = Long.parseLong(in.readLine());
		long result = K / 500 * 1000;
		K = K % 500;
		result += K /  5 * 5;
		System.out.println(result);
	}

	void calc() {
	}

	void showResult() {
	}

}
