import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int X;
		Scanner sc = new Scanner(System.in);
		X = Integer.parseInt(sc.next());
		int mod = 0;
		int c_500 = X / 500;
		mod = X % 500;
		int c_5 = mod / 5;
		System.out.println(c_500 * 1000 + c_5 * 5);

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		int X;
		Scanner sc = new Scanner(System.in);
		X = Integer.parseInt(sc.next());
		int mod = 0;
		int c_500 = X / 500;
		mod = X % 500;
		int c_5 = mod / 5;
		System.out.println(c_500 * 1000 + c_5 * 5);

	}

} Main public static void main(String[] args) {
		int X;
		Scanner sc = new Scanner(System.in);
		X = Integer.parseInt(sc.next());
		int mod = 0;
		int c_500 = X / 500;
		mod = X % 500;
		int c_5 = mod / 5;
		System.out.println(c_500 * 1000 + c_5 * 5);

	} main {
		int X;
		Scanner sc = new Scanner(System.in);
		X = Integer.parseInt(sc.next());
		int mod = 0;
		int c_500 = X / 500;
		mod = X % 500;
		int c_5 = mod / 5;
		System.out.println(c_500 * 1000 + c_5 * 5);

	} int X; X Scanner sc = new Scanner(System.in); sc new Scanner(System.in) X = Integer.parseInt(sc.next()) X Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int mod = 0; mod 0 int c_500 = X / 500; c_500 X / 500 X 500 mod = X % 500 mod X % 500 X 500 int c_5 = mod / 5; c_5 mod / 5 mod 5 System.out.println(c_500 * 1000 + c_5 * 5) System.out.println System.out System System.out c_500 * 1000 + c_5 * 5 c_500 * 1000 c_500 1000 c_5 * 5 c_5 5 String[] args args public class Main {

	public static void main(String[] args) {
		int X;
		Scanner sc = new Scanner(System.in);
		X = Integer.parseInt(sc.next());
		int mod = 0;
		int c_500 = X / 500;
		mod = X % 500;
		int c_5 = mod / 5;
		System.out.println(c_500 * 1000 + c_5 * 5);

	}

} public class Main {

	public static void main(String[] args) {
		int X;
		Scanner sc = new Scanner(System.in);
		X = Integer.parseInt(sc.next());
		int mod = 0;
		int c_500 = X / 500;
		mod = X % 500;
		int c_5 = mod / 5;
		System.out.println(c_500 * 1000 + c_5 * 5);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int X;
		Scanner sc = new Scanner(System.in);
		X = Integer.parseInt(sc.next());
		int mod = 0;
		int c_500 = X / 500;
		mod = X % 500;
		int c_5 = mod / 5;
		System.out.println(c_500 * 1000 + c_5 * 5);

	}

}