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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// ------------------------------------------------

		int x = Integer.parseInt(sc.next());

		int ret = 0;

		ret += (x / 500) * 1000;
		x %= 500;
		ret += (x / 5) * 5;

		out.println(ret);

		// ------------------------------------------------
		sc.close();
		out.flush();
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// ------------------------------------------------

		int x = Integer.parseInt(sc.next());

		int ret = 0;

		ret += (x / 500) * 1000;
		x %= 500;
		ret += (x / 5) * 5;

		out.println(ret);

		// ------------------------------------------------
		sc.close();
		out.flush();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// ------------------------------------------------

		int x = Integer.parseInt(sc.next());

		int ret = 0;

		ret += (x / 500) * 1000;
		x %= 500;
		ret += (x / 5) * 5;

		out.println(ret);

		// ------------------------------------------------
		sc.close();
		out.flush();
	} main {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// ------------------------------------------------

		int x = Integer.parseInt(sc.next());

		int ret = 0;

		ret += (x / 500) * 1000;
		x %= 500;
		ret += (x / 5) * 5;

		out.println(ret);

		// ------------------------------------------------
		sc.close();
		out.flush();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int x = Integer.parseInt(sc.next()); x Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int ret = 0; ret 0 ret += (x / 500) * 1000 ret (x / 500) * 1000 (x / 500) x 500 1000 x %= 500 x 500 ret += (x / 5) * 5 ret (x / 5) * 5 (x / 5) x 5 5 out.println(ret) out.println out ret sc.close() sc.close sc out.flush() out.flush out String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// ------------------------------------------------

		int x = Integer.parseInt(sc.next());

		int ret = 0;

		ret += (x / 500) * 1000;
		x %= 500;
		ret += (x / 5) * 5;

		out.println(ret);

		// ------------------------------------------------
		sc.close();
		out.flush();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// ------------------------------------------------

		int x = Integer.parseInt(sc.next());

		int ret = 0;

		ret += (x / 500) * 1000;
		x %= 500;
		ret += (x / 5) * 5;

		out.println(ret);

		// ------------------------------------------------
		sc.close();
		out.flush();
	}
} Main
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// ------------------------------------------------

		int x = Integer.parseInt(sc.next());

		int ret = 0;

		ret += (x / 500) * 1000;
		x %= 500;
		ret += (x / 5) * 5;

		out.println(ret);

		// ------------------------------------------------
		sc.close();
		out.flush();
	}
}