import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int max = 0;
		int maxnum = -1;
		int secmax = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > secmax) {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			}
//			System.out.println("i:" + i + ", m:" + max + ", s:" + secmax);
		}

		loop: for (int i = 0; i < n; i++) {
			if (max != secmax) {
				if (i == maxnum) {
					System.out.println(secmax);
					continue loop;
				}
			}

			System.out.println(max);
		}

		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int max = 0;
		int maxnum = -1;
		int secmax = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > secmax) {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			}
//			System.out.println("i:" + i + ", m:" + max + ", s:" + secmax);
		}

		loop: for (int i = 0; i < n; i++) {
			if (max != secmax) {
				if (i == maxnum) {
					System.out.println(secmax);
					continue loop;
				}
			}

			System.out.println(max);
		}

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

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int max = 0;
		int maxnum = -1;
		int secmax = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > secmax) {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			}
//			System.out.println("i:" + i + ", m:" + max + ", s:" + secmax);
		}

		loop: for (int i = 0; i < n; i++) {
			if (max != secmax) {
				if (i == maxnum) {
					System.out.println(secmax);
					continue loop;
				}
			}

			System.out.println(max);
		}

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int max = 0;
		int maxnum = -1;
		int secmax = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > secmax) {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			}
//			System.out.println("i:" + i + ", m:" + max + ", s:" + secmax);
		}

		loop: for (int i = 0; i < n; i++) {
			if (max != secmax) {
				if (i == maxnum) {
					System.out.println(secmax);
					continue loop;
				}
			}

			System.out.println(max);
		}

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = sc.nextInt();
		} {
			a[i] = sc.nextInt();
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int max = 0; max 0 int maxnum = -1; maxnum -1 1 int secmax = 0; secmax 0 for (int i = 0; i < n; i++) {
			if (a[i] > secmax) {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			}
//			System.out.println("i:" + i + ", m:" + max + ", s:" + secmax);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (a[i] > secmax) {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			}
//			System.out.println("i:" + i + ", m:" + max + ", s:" + secmax);
		} {
			if (a[i] > secmax) {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			}
//			System.out.println("i:" + i + ", m:" + max + ", s:" + secmax);
		} if (a[i] > secmax) {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			} a[i] > secmax a[i] a i secmax {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			} if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				} a[i] > max a[i] a i max {
					secmax = max;
					max = a[i];
					maxnum = i;
				} secmax = max secmax max max = a[i] max a[i] a i maxnum = i maxnum i {
					secmax = a[i];
				} secmax = a[i] secmax a[i] a i sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int max = 0;
		int maxnum = -1;
		int secmax = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > secmax) {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			}
//			System.out.println("i:" + i + ", m:" + max + ", s:" + secmax);
		}

		loop: for (int i = 0; i < n; i++) {
			if (max != secmax) {
				if (i == maxnum) {
					System.out.println(secmax);
					continue loop;
				}
			}

			System.out.println(max);
		}

		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int max = 0;
		int maxnum = -1;
		int secmax = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > secmax) {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			}
//			System.out.println("i:" + i + ", m:" + max + ", s:" + secmax);
		}

		loop: for (int i = 0; i < n; i++) {
			if (max != secmax) {
				if (i == maxnum) {
					System.out.println(secmax);
					continue loop;
				}
			}

			System.out.println(max);
		}

		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int max = 0;
		int maxnum = -1;
		int secmax = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > secmax) {

				if (a[i] > max) {
					secmax = max;
					max = a[i];
					maxnum = i;
				} else {
					secmax = a[i];
				}

			}
//			System.out.println("i:" + i + ", m:" + max + ", s:" + secmax);
		}

		loop: for (int i = 0; i < n; i++) {
			if (max != secmax) {
				if (i == maxnum) {
					System.out.println(secmax);
					continue loop;
				}
			}

			System.out.println(max);
		}

		sc.close();
	}
}