import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = x / 500;
		x %= 500;
		int z = x / 5;
		System.out.println(y * 1000 + z * 5);

	}

} 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 y = x / 500;
		x %= 500;
		int z = x / 5;
		System.out.println(y * 1000 + z * 5);

	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = x / 500;
		x %= 500;
		int z = x / 5;
		System.out.println(y * 1000 + z * 5);

	} main {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = x / 500;
		x %= 500;
		int z = x / 5;
		System.out.println(y * 1000 + z * 5);

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = x / 500;
		x %= 500;
		int z = x / 5;
		System.out.println(y * 1000 + z * 5);

	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = x / 500;
		x %= 500;
		int z = x / 5;
		System.out.println(y * 1000 + z * 5);

	}

} 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 y = x / 500;
		x %= 500;
		int z = x / 5;
		System.out.println(y * 1000 + z * 5);

	}

}
