import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int a1 = 0;
		int a2 = 0;
		int mi = 0;
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			if (a2 > a)
				continue;
			a2 = a;
			if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			}
		}
		for(int i=0;i<n;i++)
			if(i==mi)
				System.out.println(a2);
			else
				System.out.println(a1);
		in.close();
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Comparator; Comparator java.util import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int a1 = 0;
		int a2 = 0;
		int mi = 0;
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			if (a2 > a)
				continue;
			a2 = a;
			if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			}
		}
		for(int i=0;i<n;i++)
			if(i==mi)
				System.out.println(a2);
			else
				System.out.println(a1);
		in.close();
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int a1 = 0;
		int a2 = 0;
		int mi = 0;
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			if (a2 > a)
				continue;
			a2 = a;
			if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			}
		}
		for(int i=0;i<n;i++)
			if(i==mi)
				System.out.println(a2);
			else
				System.out.println(a1);
		in.close();
	} main {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int a1 = 0;
		int a2 = 0;
		int mi = 0;
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			if (a2 > a)
				continue;
			a2 = a;
			if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			}
		}
		for(int i=0;i<n;i++)
			if(i==mi)
				System.out.println(a2);
			else
				System.out.println(a1);
		in.close();
	} Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); in new Scanner(new BufferedReader(new InputStreamReader(System.in))) int n = in.nextInt(); n in.nextInt() in.nextInt in int a1 = 0; a1 0 int a2 = 0; a2 0 int mi = 0; mi 0 for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			if (a2 > a)
				continue;
			a2 = a;
			if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int a = in.nextInt();
			if (a2 > a)
				continue;
			a2 = a;
			if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			}
		} {
			int a = in.nextInt();
			if (a2 > a)
				continue;
			a2 = a;
			if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			}
		} int a = in.nextInt(); a in.nextInt() in.nextInt in if (a2 > a)
				continue; a2 > a a2 a continue; a2 = a a2 a if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			} a1 < a2 a1 a2 {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			} int t = a1; t a1 a1 = a2 a1 a2 a2 = t a2 t mi = i mi i for(int i=0;i<n;i++)
			if(i==mi)
				System.out.println(a2);
			else
				System.out.println(a1); int i=0; int i=0; i 0 i<n i n i++ i++ i if(i==mi)
				System.out.println(a2);
			else
				System.out.println(a1); if(i==mi)
				System.out.println(a2);
			else
				System.out.println(a1); i==mi i mi System.out.println(a2) System.out.println System.out System System.out a2 System.out.println(a1) System.out.println System.out System System.out a1 in.close() in.close in String[] args args public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int a1 = 0;
		int a2 = 0;
		int mi = 0;
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			if (a2 > a)
				continue;
			a2 = a;
			if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			}
		}
		for(int i=0;i<n;i++)
			if(i==mi)
				System.out.println(a2);
			else
				System.out.println(a1);
		in.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int a1 = 0;
		int a2 = 0;
		int mi = 0;
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			if (a2 > a)
				continue;
			a2 = a;
			if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			}
		}
		for(int i=0;i<n;i++)
			if(i==mi)
				System.out.println(a2);
			else
				System.out.println(a1);
		in.close();
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int a1 = 0;
		int a2 = 0;
		int mi = 0;
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			if (a2 > a)
				continue;
			a2 = a;
			if (a1 < a2) {
				int t = a1;
				a1 = a2;
				a2 = t;
				mi = i;
			}
		}
		for(int i=0;i<n;i++)
			if(i==mi)
				System.out.println(a2);
			else
				System.out.println(a1);
		in.close();
	}
}
