import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();
		int c500 = X / 500;
		X %= 500;
		int c5 = X / 5;

		System.out.println(1000*c500 + 5*c5);

	}

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

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();
		int c500 = X / 500;
		X %= 500;
		int c5 = X / 5;

		System.out.println(1000*c500 + 5*c5);

	}

} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();
		int c500 = X / 500;
		X %= 500;
		int c5 = X / 5;

		System.out.println(1000*c500 + 5*c5);

	} main {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();
		int c500 = X / 500;
		X %= 500;
		int c5 = X / 5;

		System.out.println(1000*c500 + 5*c5);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int X = scan.nextInt(); X scan.nextInt() scan.nextInt scan int c500 = X / 500; c500 X / 500 X 500 X %= 500 X 500 int c5 = X / 5; c5 X / 5 X 5 System.out.println(1000*c500 + 5*c5) System.out.println System.out System System.out 1000*c500 + 5*c5 1000*c500 1000 c500 5*c5 5 c5 String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();
		int c500 = X / 500;
		X %= 500;
		int c5 = X / 5;

		System.out.println(1000*c500 + 5*c5);

	}

} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();
		int c500 = X / 500;
		X %= 500;
		int c5 = X / 5;

		System.out.println(1000*c500 + 5*c5);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();
		int c500 = X / 500;
		X %= 500;
		int c5 = X / 5;

		System.out.println(1000*c500 + 5*c5);

	}

}