import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		int happiness = 0;

		happiness += n / 500 * 1000;
		n = n % 500;

		happiness += n / 5 * 5;

		System.out.println(happiness);

	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		int happiness = 0;

		happiness += n / 500 * 1000;
		n = n % 500;

		happiness += n / 5 * 5;

		System.out.println(happiness);

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		int happiness = 0;

		happiness += n / 500 * 1000;
		n = n % 500;

		happiness += n / 5 * 5;

		System.out.println(happiness);

	} main {
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		int happiness = 0;

		happiness += n / 500 * 1000;
		n = n % 500;

		happiness += n / 5 * 5;

		System.out.println(happiness);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long n = Long.parseLong(sc.next()); n Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc int happiness = 0; happiness 0 happiness += n / 500 * 1000 happiness n / 500 * 1000 n / 500 n 500 1000 n = n % 500 n n % 500 n 500 happiness += n / 5 * 5 happiness n / 5 * 5 n / 5 n 5 5 System.out.println(happiness) System.out.println System.out System System.out happiness String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		int happiness = 0;

		happiness += n / 500 * 1000;
		n = n % 500;

		happiness += n / 5 * 5;

		System.out.println(happiness);

	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		int happiness = 0;

		happiness += n / 500 * 1000;
		n = n % 500;

		happiness += n / 5 * 5;

		System.out.println(happiness);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		int happiness = 0;

		happiness += n / 500 * 1000;
		n = n % 500;

		happiness += n / 5 * 5;

		System.out.println(happiness);

	}

}
