import java.util.Scanner;

public class Main {

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

		// input
		final int NUM = scan.nextInt();
		int[] nums = new int[NUM];
		int first = Integer.MIN_VALUE;
		int second = Integer.MIN_VALUE;
		for(int i = 0; i < NUM; i++){
			nums[i] = scan.nextInt();
			if(nums[i] > first && first == second){
				first = nums[i];
			} else if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			}
		}

		// answer
		for(int i = 0; i < NUM; i++){
			if(nums[i] == first){
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}

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

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

		// input
		final int NUM = scan.nextInt();
		int[] nums = new int[NUM];
		int first = Integer.MIN_VALUE;
		int second = Integer.MIN_VALUE;
		for(int i = 0; i < NUM; i++){
			nums[i] = scan.nextInt();
			if(nums[i] > first && first == second){
				first = nums[i];
			} else if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			}
		}

		// answer
		for(int i = 0; i < NUM; i++){
			if(nums[i] == first){
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}

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

		// input
		final int NUM = scan.nextInt();
		int[] nums = new int[NUM];
		int first = Integer.MIN_VALUE;
		int second = Integer.MIN_VALUE;
		for(int i = 0; i < NUM; i++){
			nums[i] = scan.nextInt();
			if(nums[i] > first && first == second){
				first = nums[i];
			} else if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			}
		}

		// answer
		for(int i = 0; i < NUM; i++){
			if(nums[i] == first){
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}

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

		// input
		final int NUM = scan.nextInt();
		int[] nums = new int[NUM];
		int first = Integer.MIN_VALUE;
		int second = Integer.MIN_VALUE;
		for(int i = 0; i < NUM; i++){
			nums[i] = scan.nextInt();
			if(nums[i] > first && first == second){
				first = nums[i];
			} else if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			}
		}

		// answer
		for(int i = 0; i < NUM; i++){
			if(nums[i] == first){
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) final int NUM = scan.nextInt(); NUM scan.nextInt() scan.nextInt scan int[] nums = new int[NUM]; nums new int[NUM] NUM int first = Integer.MIN_VALUE; first Integer.MIN_VALUE Integer Integer.MIN_VALUE int second = Integer.MIN_VALUE; second Integer.MIN_VALUE Integer Integer.MIN_VALUE for(int i = 0; i < NUM; i++){
			nums[i] = scan.nextInt();
			if(nums[i] > first && first == second){
				first = nums[i];
			} else if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			}
		} int i = 0; int i = 0; i 0 i < NUM i NUM i++ i++ i {
			nums[i] = scan.nextInt();
			if(nums[i] > first && first == second){
				first = nums[i];
			} else if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			}
		} {
			nums[i] = scan.nextInt();
			if(nums[i] > first && first == second){
				first = nums[i];
			} else if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			}
		} nums[i] = scan.nextInt() nums[i] nums i scan.nextInt() scan.nextInt scan if(nums[i] > first && first == second){
				first = nums[i];
			} else if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			} nums[i] > first && first == second nums[i] > first nums[i] nums i first first == second first second {
				first = nums[i];
			} first = nums[i] first nums[i] nums i if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			} nums[i] > first nums[i] nums i first {
				first = nums[i];
			} first = nums[i] first nums[i] nums i if (nums[i] > second){
				second = nums[i];
			} nums[i] > second nums[i] nums i second {
				second = nums[i];
			} second = nums[i] second nums[i] nums i for(int i = 0; i < NUM; i++){
			if(nums[i] == first){
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		} int i = 0; int i = 0; i 0 i < NUM i NUM i++ i++ i {
			if(nums[i] == first){
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		} {
			if(nums[i] == first){
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		} if(nums[i] == first){
				System.out.println(second);
			} else {
				System.out.println(first);
			} nums[i] == first nums[i] nums i first {
				System.out.println(second);
			} System.out.println(second) System.out.println System.out System System.out second {
				System.out.println(first);
			} System.out.println(first) System.out.println System.out System System.out first String[] args args public class Main {

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

		// input
		final int NUM = scan.nextInt();
		int[] nums = new int[NUM];
		int first = Integer.MIN_VALUE;
		int second = Integer.MIN_VALUE;
		for(int i = 0; i < NUM; i++){
			nums[i] = scan.nextInt();
			if(nums[i] > first && first == second){
				first = nums[i];
			} else if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			}
		}

		// answer
		for(int i = 0; i < NUM; i++){
			if(nums[i] == first){
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}

	}
} public class Main {

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

		// input
		final int NUM = scan.nextInt();
		int[] nums = new int[NUM];
		int first = Integer.MIN_VALUE;
		int second = Integer.MIN_VALUE;
		for(int i = 0; i < NUM; i++){
			nums[i] = scan.nextInt();
			if(nums[i] > first && first == second){
				first = nums[i];
			} else if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			}
		}

		// answer
		for(int i = 0; i < NUM; i++){
			if(nums[i] == first){
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}

	}
} Main
import java.util.Scanner;

public class Main {

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

		// input
		final int NUM = scan.nextInt();
		int[] nums = new int[NUM];
		int first = Integer.MIN_VALUE;
		int second = Integer.MIN_VALUE;
		for(int i = 0; i < NUM; i++){
			nums[i] = scan.nextInt();
			if(nums[i] > first && first == second){
				first = nums[i];
			} else if (nums[i] > first){
				first = nums[i];
			} else if (nums[i] > second){
				second = nums[i];
			}
		}

		// answer
		for(int i = 0; i < NUM; i++){
			if(nums[i] == first){
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}

	}
}
