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 n = 0 ; n < N ; n++ ) {
			A[n] = sc.nextInt();
		}

		int first = 0;
		int second = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			if ( first <= A[i] ) {
				second = first;
				first = A[i];
			} else if ( second <= A[i]) {
				second = A[i];
			}
		}

		StringBuffer ans = new StringBuffer();
		for ( int i = 0 ; i < N ; i++ ) {
			if ( A[i] == first ) {
				ans.append(second);
			} else {
				ans.append(first);
			}
			ans.append("\n");
		}
		System.out.println(ans.toString());
	}
} 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 n = 0 ; n < N ; n++ ) {
			A[n] = sc.nextInt();
		}

		int first = 0;
		int second = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			if ( first <= A[i] ) {
				second = first;
				first = A[i];
			} else if ( second <= A[i]) {
				second = A[i];
			}
		}

		StringBuffer ans = new StringBuffer();
		for ( int i = 0 ; i < N ; i++ ) {
			if ( A[i] == first ) {
				ans.append(second);
			} else {
				ans.append(first);
			}
			ans.append("\n");
		}
		System.out.println(ans.toString());
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int[] A = new int[N];
		for ( int n = 0 ; n < N ; n++ ) {
			A[n] = sc.nextInt();
		}

		int first = 0;
		int second = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			if ( first <= A[i] ) {
				second = first;
				first = A[i];
			} else if ( second <= A[i]) {
				second = A[i];
			}
		}

		StringBuffer ans = new StringBuffer();
		for ( int i = 0 ; i < N ; i++ ) {
			if ( A[i] == first ) {
				ans.append(second);
			} else {
				ans.append(first);
			}
			ans.append("\n");
		}
		System.out.println(ans.toString());
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int[] A = new int[N];
		for ( int n = 0 ; n < N ; n++ ) {
			A[n] = sc.nextInt();
		}

		int first = 0;
		int second = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			if ( first <= A[i] ) {
				second = first;
				first = A[i];
			} else if ( second <= A[i]) {
				second = A[i];
			}
		}

		StringBuffer ans = new StringBuffer();
		for ( int i = 0 ; i < N ; i++ ) {
			if ( A[i] == first ) {
				ans.append(second);
			} else {
				ans.append(first);
			}
			ans.append("\n");
		}
		System.out.println(ans.toString());
	} 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 n = 0 ; n < N ; n++ ) {
			A[n] = sc.nextInt();
		} int n = 0 ; int n = 0 ; n 0 n < N n N n++ n++ n {
			A[n] = sc.nextInt();
		} {
			A[n] = sc.nextInt();
		} A[n] = sc.nextInt() A[n] A n sc.nextInt() sc.nextInt sc int first = 0; first 0 int second = 0; second 0 for ( int i = 0 ; i < N ; i++ ) {
			if ( first <= A[i] ) {
				second = first;
				first = A[i];
			} else if ( second <= A[i]) {
				second = A[i];
			}
		} int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
			if ( first <= A[i] ) {
				second = first;
				first = A[i];
			} else if ( second <= A[i]) {
				second = A[i];
			}
		} {
			if ( first <= A[i] ) {
				second = first;
				first = A[i];
			} else if ( second <= A[i]) {
				second = A[i];
			}
		} if ( first <= A[i] ) {
				second = first;
				first = A[i];
			} else if ( second <= A[i]) {
				second = A[i];
			} first <= A[i] first A[i] A i {
				second = first;
				first = A[i];
			} second = first second first first = A[i] first A[i] A i if ( second <= A[i]) {
				second = A[i];
			} second <= A[i] second A[i] A i {
				second = A[i];
			} second = A[i] second A[i] A i StringBuffer ans = new StringBuffer(); ans new StringBuffer() for ( int i = 0 ; i < N ; i++ ) {
			if ( A[i] == first ) {
				ans.append(second);
			} else {
				ans.append(first);
			}
			ans.append("\n");
		} int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
			if ( A[i] == first ) {
				ans.append(second);
			} else {
				ans.append(first);
			}
			ans.append("\n");
		} {
			if ( A[i] == first ) {
				ans.append(second);
			} else {
				ans.append(first);
			}
			ans.append("\n");
		} if ( A[i] == first ) {
				ans.append(second);
			} else {
				ans.append(first);
			} A[i] == first A[i] A i first {
				ans.append(second);
			} ans.append(second) ans.append ans second {
				ans.append(first);
			} ans.append(first) ans.append ans first ans.append("\n") ans.append ans "\n" System.out.println(ans.toString()) System.out.println System.out System System.out ans.toString() ans.toString ans 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 n = 0 ; n < N ; n++ ) {
			A[n] = sc.nextInt();
		}

		int first = 0;
		int second = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			if ( first <= A[i] ) {
				second = first;
				first = A[i];
			} else if ( second <= A[i]) {
				second = A[i];
			}
		}

		StringBuffer ans = new StringBuffer();
		for ( int i = 0 ; i < N ; i++ ) {
			if ( A[i] == first ) {
				ans.append(second);
			} else {
				ans.append(first);
			}
			ans.append("\n");
		}
		System.out.println(ans.toString());
	}
} 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 n = 0 ; n < N ; n++ ) {
			A[n] = sc.nextInt();
		}

		int first = 0;
		int second = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			if ( first <= A[i] ) {
				second = first;
				first = A[i];
			} else if ( second <= A[i]) {
				second = A[i];
			}
		}

		StringBuffer ans = new StringBuffer();
		for ( int i = 0 ; i < N ; i++ ) {
			if ( A[i] == first ) {
				ans.append(second);
			} else {
				ans.append(first);
			}
			ans.append("\n");
		}
		System.out.println(ans.toString());
	}
} 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 n = 0 ; n < N ; n++ ) {
			A[n] = sc.nextInt();
		}

		int first = 0;
		int second = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			if ( first <= A[i] ) {
				second = first;
				first = A[i];
			} else if ( second <= A[i]) {
				second = A[i];
			}
		}

		StringBuffer ans = new StringBuffer();
		for ( int i = 0 ; i < N ; i++ ) {
			if ( A[i] == first ) {
				ans.append(second);
			} else {
				ans.append(first);
			}
			ans.append("\n");
		}
		System.out.println(ans.toString());
	}
}
