import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out); 
		
		int N = Integer.parseInt(sc.next());
		int input;
		int first = 0, second = 0;
		int first_i = 0;
		
		for(int i = 0; i < N; i++) {
			input = Integer.parseInt(sc.next());
			if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			}
		}
		
		for (int i = 0; i < N; i++ ) {
			if (i == first_i) {
				out.println(second);
			} else {
				out.println(first);
			}
		}
		
		out.flush();
		sc.close();
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out); 
		
		int N = Integer.parseInt(sc.next());
		int input;
		int first = 0, second = 0;
		int first_i = 0;
		
		for(int i = 0; i < N; i++) {
			input = Integer.parseInt(sc.next());
			if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			}
		}
		
		for (int i = 0; i < N; i++ ) {
			if (i == first_i) {
				out.println(second);
			} else {
				out.println(first);
			}
		}
		
		out.flush();
		sc.close();
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out); 
		
		int N = Integer.parseInt(sc.next());
		int input;
		int first = 0, second = 0;
		int first_i = 0;
		
		for(int i = 0; i < N; i++) {
			input = Integer.parseInt(sc.next());
			if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			}
		}
		
		for (int i = 0; i < N; i++ ) {
			if (i == first_i) {
				out.println(second);
			} else {
				out.println(first);
			}
		}
		
		out.flush();
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out); 
		
		int N = Integer.parseInt(sc.next());
		int input;
		int first = 0, second = 0;
		int first_i = 0;
		
		for(int i = 0; i < N; i++) {
			input = Integer.parseInt(sc.next());
			if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			}
		}
		
		for (int i = 0; i < N; i++ ) {
			if (i == first_i) {
				out.println(second);
			} else {
				out.println(first);
			}
		}
		
		out.flush();
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int input; input int first = 0 first 0 second = 0; second 0 int first_i = 0; first_i 0 for(int i = 0; i < N; i++) {
			input = Integer.parseInt(sc.next());
			if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			input = Integer.parseInt(sc.next());
			if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			}
		} {
			input = Integer.parseInt(sc.next());
			if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			}
		} input = Integer.parseInt(sc.next()) input Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			} first < input first input {
				second = first;
				first = input;
				first_i = i;
				
			} second = first second first first = input first input first_i = i first_i i if (second < input) {
				second = input;
			} second < input second input {
				second = input;
			} second = input second input for (int i = 0; i < N; i++ ) {
			if (i == first_i) {
				out.println(second);
			} else {
				out.println(first);
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (i == first_i) {
				out.println(second);
			} else {
				out.println(first);
			}
		} {
			if (i == first_i) {
				out.println(second);
			} else {
				out.println(first);
			}
		} if (i == first_i) {
				out.println(second);
			} else {
				out.println(first);
			} i == first_i i first_i {
				out.println(second);
			} out.println(second) out.println out second {
				out.println(first);
			} out.println(first) out.println out first out.flush() out.flush out sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out); 
		
		int N = Integer.parseInt(sc.next());
		int input;
		int first = 0, second = 0;
		int first_i = 0;
		
		for(int i = 0; i < N; i++) {
			input = Integer.parseInt(sc.next());
			if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			}
		}
		
		for (int i = 0; i < N; i++ ) {
			if (i == first_i) {
				out.println(second);
			} else {
				out.println(first);
			}
		}
		
		out.flush();
		sc.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out); 
		
		int N = Integer.parseInt(sc.next());
		int input;
		int first = 0, second = 0;
		int first_i = 0;
		
		for(int i = 0; i < N; i++) {
			input = Integer.parseInt(sc.next());
			if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			}
		}
		
		for (int i = 0; i < N; i++ ) {
			if (i == first_i) {
				out.println(second);
			} else {
				out.println(first);
			}
		}
		
		out.flush();
		sc.close();
	}

} Main
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out); 
		
		int N = Integer.parseInt(sc.next());
		int input;
		int first = 0, second = 0;
		int first_i = 0;
		
		for(int i = 0; i < N; i++) {
			input = Integer.parseInt(sc.next());
			if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			}
		}
		
		for (int i = 0; i < N; i++ ) {
			if (i == first_i) {
				out.println(second);
			} else {
				out.println(first);
			}
		}
		
		out.flush();
		sc.close();
	}

}
