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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int []a = new int[n];
		int []b = new int[n];
		int high = 0;

		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
			b[i] = a[i];
			high = Math.max(high, a[i]);
		}
		Arrays.sort(b);

		for(int i = 0; i < n; i++) {
			if(a[i]!= high) {
				System.out.println(high);
			}else {
				System.out.println(b[n-2]);
			}
		}













	/*	for(int i = 0; i < max.length; i++) {
			max[i] = Integer.MIN_VALUE;
		}

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(j==i) {
					continue;
				}else {
					max[i] = Math.max(max[i], a[j]);
				}
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.println(max[i]);
		}*/

	}

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int []a = new int[n];
		int []b = new int[n];
		int high = 0;

		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
			b[i] = a[i];
			high = Math.max(high, a[i]);
		}
		Arrays.sort(b);

		for(int i = 0; i < n; i++) {
			if(a[i]!= high) {
				System.out.println(high);
			}else {
				System.out.println(b[n-2]);
			}
		}













	/*	for(int i = 0; i < max.length; i++) {
			max[i] = Integer.MIN_VALUE;
		}

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(j==i) {
					continue;
				}else {
					max[i] = Math.max(max[i], a[j]);
				}
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.println(max[i]);
		}*/

	}

} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int []a = new int[n];
		int []b = new int[n];
		int high = 0;

		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
			b[i] = a[i];
			high = Math.max(high, a[i]);
		}
		Arrays.sort(b);

		for(int i = 0; i < n; i++) {
			if(a[i]!= high) {
				System.out.println(high);
			}else {
				System.out.println(b[n-2]);
			}
		}













	/*	for(int i = 0; i < max.length; i++) {
			max[i] = Integer.MIN_VALUE;
		}

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(j==i) {
					continue;
				}else {
					max[i] = Math.max(max[i], a[j]);
				}
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.println(max[i]);
		}*/

	} main {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int []a = new int[n];
		int []b = new int[n];
		int high = 0;

		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
			b[i] = a[i];
			high = Math.max(high, a[i]);
		}
		Arrays.sort(b);

		for(int i = 0; i < n; i++) {
			if(a[i]!= high) {
				System.out.println(high);
			}else {
				System.out.println(b[n-2]);
			}
		}













	/*	for(int i = 0; i < max.length; i++) {
			max[i] = Integer.MIN_VALUE;
		}

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(j==i) {
					continue;
				}else {
					max[i] = Math.max(max[i], a[j]);
				}
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.println(max[i]);
		}*/

	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int []a = new int[n]; a new int[n] n int []b = new int[n]; b new int[n] n int high = 0; high 0 for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
			b[i] = a[i];
			high = Math.max(high, a[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = stdIn.nextInt();
			b[i] = a[i];
			high = Math.max(high, a[i]);
		} {
			a[i] = stdIn.nextInt();
			b[i] = a[i];
			high = Math.max(high, a[i]);
		} a[i] = stdIn.nextInt() a[i] a i stdIn.nextInt() stdIn.nextInt stdIn b[i] = a[i] b[i] b i a[i] a i high = Math.max(high, a[i]) high Math.max(high, a[i]) Math.max Math high a[i] a i Arrays.sort(b) Arrays.sort Arrays b for(int i = 0; i < n; i++) {
			if(a[i]!= high) {
				System.out.println(high);
			}else {
				System.out.println(b[n-2]);
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if(a[i]!= high) {
				System.out.println(high);
			}else {
				System.out.println(b[n-2]);
			}
		} {
			if(a[i]!= high) {
				System.out.println(high);
			}else {
				System.out.println(b[n-2]);
			}
		} if(a[i]!= high) {
				System.out.println(high);
			}else {
				System.out.println(b[n-2]);
			} a[i]!= high a[i] a i high {
				System.out.println(high);
			} System.out.println(high) System.out.println System.out System System.out high {
				System.out.println(b[n-2]);
			} System.out.println(b[n-2]) System.out.println System.out System System.out b[n-2] b n-2 n 2 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int []a = new int[n];
		int []b = new int[n];
		int high = 0;

		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
			b[i] = a[i];
			high = Math.max(high, a[i]);
		}
		Arrays.sort(b);

		for(int i = 0; i < n; i++) {
			if(a[i]!= high) {
				System.out.println(high);
			}else {
				System.out.println(b[n-2]);
			}
		}













	/*	for(int i = 0; i < max.length; i++) {
			max[i] = Integer.MIN_VALUE;
		}

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(j==i) {
					continue;
				}else {
					max[i] = Math.max(max[i], a[j]);
				}
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.println(max[i]);
		}*/

	}

} public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int []a = new int[n];
		int []b = new int[n];
		int high = 0;

		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
			b[i] = a[i];
			high = Math.max(high, a[i]);
		}
		Arrays.sort(b);

		for(int i = 0; i < n; i++) {
			if(a[i]!= high) {
				System.out.println(high);
			}else {
				System.out.println(b[n-2]);
			}
		}













	/*	for(int i = 0; i < max.length; i++) {
			max[i] = Integer.MIN_VALUE;
		}

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(j==i) {
					continue;
				}else {
					max[i] = Math.max(max[i], a[j]);
				}
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.println(max[i]);
		}*/

	}

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int []a = new int[n];
		int []b = new int[n];
		int high = 0;

		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
			b[i] = a[i];
			high = Math.max(high, a[i]);
		}
		Arrays.sort(b);

		for(int i = 0; i < n; i++) {
			if(a[i]!= high) {
				System.out.println(high);
			}else {
				System.out.println(b[n-2]);
			}
		}













	/*	for(int i = 0; i < max.length; i++) {
			max[i] = Integer.MIN_VALUE;
		}

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(j==i) {
					continue;
				}else {
					max[i] = Math.max(max[i], a[j]);
				}
			}
		}
		for(int i = 0; i < n; i++) {
			System.out.println(max[i]);
		}*/

	}

}
