import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		sc.close();

		int util = 0;
		util += (X / 500) * 1000;
		int rest = X % 500;
		util += (rest / 5) * 5;
		System.out.println(util);

	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		sc.close();

		int util = 0;
		util += (X / 500) * 1000;
		int rest = X % 500;
		util += (rest / 5) * 5;
		System.out.println(util);

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		sc.close();

		int util = 0;
		util += (X / 500) * 1000;
		int rest = X % 500;
		util += (rest / 5) * 5;
		System.out.println(util);

	} main {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		sc.close();

		int util = 0;
		util += (X / 500) * 1000;
		int rest = X % 500;
		util += (rest / 5) * 5;
		System.out.println(util);

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		sc.close();

		int util = 0;
		util += (X / 500) * 1000;
		int rest = X % 500;
		util += (rest / 5) * 5;
		System.out.println(util);

	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		sc.close();

		int util = 0;
		util += (X / 500) * 1000;
		int rest = X % 500;
		util += (rest / 5) * 5;
		System.out.println(util);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		sc.close();

		int util = 0;
		util += (X / 500) * 1000;
		int rest = X % 500;
		util += (rest / 5) * 5;
		System.out.println(util);

	}

}
