import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner n = new Scanner(System.in);

		int X = n.nextInt();

		int fiveHundred = X / 500;
		int happy = fiveHundred * 1000;
		X  = X - (fiveHundred * 500);

		int five = X / 5;
		happy = happy + (five * 5);

		System.out.println(happy);
	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String args[]) {
		Scanner n = new Scanner(System.in);

		int X = n.nextInt();

		int fiveHundred = X / 500;
		int happy = fiveHundred * 1000;
		X  = X - (fiveHundred * 500);

		int five = X / 5;
		happy = happy + (five * 5);

		System.out.println(happy);
	}

} Main public static void main(String args[]) {
		Scanner n = new Scanner(System.in);

		int X = n.nextInt();

		int fiveHundred = X / 500;
		int happy = fiveHundred * 1000;
		X  = X - (fiveHundred * 500);

		int five = X / 5;
		happy = happy + (five * 5);

		System.out.println(happy);
	} main {
		Scanner n = new Scanner(System.in);

		int X = n.nextInt();

		int fiveHundred = X / 500;
		int happy = fiveHundred * 1000;
		X  = X - (fiveHundred * 500);

		int five = X / 5;
		happy = happy + (five * 5);

		System.out.println(happy);
	} Scanner n = new Scanner(System.in); n new Scanner(System.in) int X = n.nextInt(); X n.nextInt() n.nextInt n int fiveHundred = X / 500; fiveHundred X / 500 X 500 int happy = fiveHundred * 1000; happy fiveHundred * 1000 fiveHundred 1000 X  = X - (fiveHundred * 500) X X - (fiveHundred * 500) X (fiveHundred * 500) fiveHundred 500 int five = X / 5; five X / 5 X 5 happy = happy + (five * 5) happy happy + (five * 5) happy (five * 5) five 5 System.out.println(happy) System.out.println System.out System System.out happy String args[] args public class Main {
	public static void main(String args[]) {
		Scanner n = new Scanner(System.in);

		int X = n.nextInt();

		int fiveHundred = X / 500;
		int happy = fiveHundred * 1000;
		X  = X - (fiveHundred * 500);

		int five = X / 5;
		happy = happy + (five * 5);

		System.out.println(happy);
	}

} public class Main {
	public static void main(String args[]) {
		Scanner n = new Scanner(System.in);

		int X = n.nextInt();

		int fiveHundred = X / 500;
		int happy = fiveHundred * 1000;
		X  = X - (fiveHundred * 500);

		int five = X / 5;
		happy = happy + (five * 5);

		System.out.println(happy);
	}

} Main
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner n = new Scanner(System.in);

		int X = n.nextInt();

		int fiveHundred = X / 500;
		int happy = fiveHundred * 1000;
		X  = X - (fiveHundred * 500);

		int five = X / 5;
		happy = happy + (five * 5);

		System.out.println(happy);
	}

}
