import java.util.Scanner;

public class Main {

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

		long money = scanner.nextLong();

		long coins500 = money / 500;
		long remainder = money % 500;
		long coins5 = remainder / 5;
		
		long maxHappy = coins500 * 1000 + coins5 * 5;
		System.out.println(maxHappy);

		scanner.close();

	}

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

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

		long money = scanner.nextLong();

		long coins500 = money / 500;
		long remainder = money % 500;
		long coins5 = remainder / 5;
		
		long maxHappy = coins500 * 1000 + coins5 * 5;
		System.out.println(maxHappy);

		scanner.close();

	}

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

		long money = scanner.nextLong();

		long coins500 = money / 500;
		long remainder = money % 500;
		long coins5 = remainder / 5;
		
		long maxHappy = coins500 * 1000 + coins5 * 5;
		System.out.println(maxHappy);

		scanner.close();

	} main {
		Scanner scanner = new Scanner(System.in);

		long money = scanner.nextLong();

		long coins500 = money / 500;
		long remainder = money % 500;
		long coins5 = remainder / 5;
		
		long maxHappy = coins500 * 1000 + coins5 * 5;
		System.out.println(maxHappy);

		scanner.close();

	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long money = scanner.nextLong(); money scanner.nextLong() scanner.nextLong scanner long coins500 = money / 500; coins500 money / 500 money 500 long remainder = money % 500; remainder money % 500 money 500 long coins5 = remainder / 5; coins5 remainder / 5 remainder 5 long maxHappy = coins500 * 1000 + coins5 * 5; maxHappy coins500 * 1000 + coins5 * 5 coins500 * 1000 coins500 1000 coins5 * 5 coins5 5 System.out.println(maxHappy) System.out.println System.out System System.out maxHappy scanner.close() scanner.close scanner String[] args args public class Main {

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

		long money = scanner.nextLong();

		long coins500 = money / 500;
		long remainder = money % 500;
		long coins5 = remainder / 5;
		
		long maxHappy = coins500 * 1000 + coins5 * 5;
		System.out.println(maxHappy);

		scanner.close();

	}

} public class Main {

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

		long money = scanner.nextLong();

		long coins500 = money / 500;
		long remainder = money % 500;
		long coins5 = remainder / 5;
		
		long maxHappy = coins500 * 1000 + coins5 * 5;
		System.out.println(maxHappy);

		scanner.close();

	}

} Main
import java.util.Scanner;

public class Main {

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

		long money = scanner.nextLong();

		long coins500 = money / 500;
		long remainder = money % 500;
		long coins5 = remainder / 5;
		
		long maxHappy = coins500 * 1000 + coins5 * 5;
		System.out.println(maxHappy);

		scanner.close();

	}

}
