import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();

		// 500円の枚数
		int count500 = X/500;
		// 余り
		int too = X%500;
		
		// 5円の枚数
		int count5 = too/5;
		
		System.out.println(count500 * 1000 + count5 * 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();

		// 500円の枚数
		int count500 = X/500;
		// 余り
		int too = X%500;
		
		// 5円の枚数
		int count5 = too/5;
		
		System.out.println(count500 * 1000 + count5 * 5);
		
	}
} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();

		// 500円の枚数
		int count500 = X/500;
		// 余り
		int too = X%500;
		
		// 5円の枚数
		int count5 = too/5;
		
		System.out.println(count500 * 1000 + count5 * 5);
		
	} main {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();

		// 500円の枚数
		int count500 = X/500;
		// 余り
		int too = X%500;
		
		// 5円の枚数
		int count5 = too/5;
		
		System.out.println(count500 * 1000 + count5 * 5);
		
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int X = scan.nextInt(); X scan.nextInt() scan.nextInt scan int count500 = X/500; count500 X/500 X 500 int too = X%500; too X%500 X 500 int count5 = too/5; count5 too/5 too 5 System.out.println(count500 * 1000 + count5 * 5) System.out.println System.out System System.out count500 * 1000 + count5 * 5 count500 * 1000 count500 1000 count5 * 5 count5 5 String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();

		// 500円の枚数
		int count500 = X/500;
		// 余り
		int too = X%500;
		
		// 5円の枚数
		int count5 = too/5;
		
		System.out.println(count500 * 1000 + count5 * 5);
		
	}
} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int X = scan.nextInt();

		// 500円の枚数
		int count500 = X/500;
		// 余り
		int too = X%500;
		
		// 5円の枚数
		int count5 = too/5;
		
		System.out.println(count500 * 1000 + count5 * 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();

		// 500円の枚数
		int count500 = X/500;
		// 余り
		int too = X%500;
		
		// 5円の枚数
		int count5 = too/5;
		
		System.out.println(count500 * 1000 + count5 * 5);
		
	}
}
