import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

		//int a = sc.nextInt();
		//List<Integer> check=new ArrayList<Integer>();
		//array = new int[h+1][w+1];
		List<Integer> list=new ArrayList<Integer>();
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//Collections.reverse(list);
		List<Integer> list_two=new ArrayList<Integer>();

		int n = sc.nextInt();

		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list.add(a);
			list_two.add(a);
		}


		Collections.sort(list, Collections.reverseOrder());
		//System.out.println(list);
		//System.out.println(list_two);
		int list_in_max = Collections.max(list_two);
		int maxIndex = list_two.indexOf(Collections.max(list_two));
		//System.out.println(maxIndex);
		if(list.get(0).equals(list.get(1))) {
			for(int i=0;n>i;i++) {
				System.out.println(list_in_max);
			}
			System.exit(0);
		}

		else {
			for(int i=0;n>i;i++) {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			}

		}
		/*

		List<Integer> list_max=new ArrayList<Integer>();

		for(int i=0;n>i;i++) {
			int max =0;

			for(int j=0;n>j;j++) {
				if(i==j)
					continue;
				if(list.get(j)>max) {
					max = list.get(j);
				}

			}
			list_max.add(max);
		}

		for(int i=0;list_max.size()>i;i++) {
			System.out.println(list_max.get(i));
		}
		*/

	}

} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		//int a = sc.nextInt();
		//List<Integer> check=new ArrayList<Integer>();
		//array = new int[h+1][w+1];
		List<Integer> list=new ArrayList<Integer>();
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//Collections.reverse(list);
		List<Integer> list_two=new ArrayList<Integer>();

		int n = sc.nextInt();

		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list.add(a);
			list_two.add(a);
		}


		Collections.sort(list, Collections.reverseOrder());
		//System.out.println(list);
		//System.out.println(list_two);
		int list_in_max = Collections.max(list_two);
		int maxIndex = list_two.indexOf(Collections.max(list_two));
		//System.out.println(maxIndex);
		if(list.get(0).equals(list.get(1))) {
			for(int i=0;n>i;i++) {
				System.out.println(list_in_max);
			}
			System.exit(0);
		}

		else {
			for(int i=0;n>i;i++) {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			}

		}
		/*

		List<Integer> list_max=new ArrayList<Integer>();

		for(int i=0;n>i;i++) {
			int max =0;

			for(int j=0;n>j;j++) {
				if(i==j)
					continue;
				if(list.get(j)>max) {
					max = list.get(j);
				}

			}
			list_max.add(max);
		}

		for(int i=0;list_max.size()>i;i++) {
			System.out.println(list_max.get(i));
		}
		*/

	}

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

		//int a = sc.nextInt();
		//List<Integer> check=new ArrayList<Integer>();
		//array = new int[h+1][w+1];
		List<Integer> list=new ArrayList<Integer>();
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//Collections.reverse(list);
		List<Integer> list_two=new ArrayList<Integer>();

		int n = sc.nextInt();

		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list.add(a);
			list_two.add(a);
		}


		Collections.sort(list, Collections.reverseOrder());
		//System.out.println(list);
		//System.out.println(list_two);
		int list_in_max = Collections.max(list_two);
		int maxIndex = list_two.indexOf(Collections.max(list_two));
		//System.out.println(maxIndex);
		if(list.get(0).equals(list.get(1))) {
			for(int i=0;n>i;i++) {
				System.out.println(list_in_max);
			}
			System.exit(0);
		}

		else {
			for(int i=0;n>i;i++) {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			}

		}
		/*

		List<Integer> list_max=new ArrayList<Integer>();

		for(int i=0;n>i;i++) {
			int max =0;

			for(int j=0;n>j;j++) {
				if(i==j)
					continue;
				if(list.get(j)>max) {
					max = list.get(j);
				}

			}
			list_max.add(max);
		}

		for(int i=0;list_max.size()>i;i++) {
			System.out.println(list_max.get(i));
		}
		*/

	} main {
		Scanner sc = new Scanner(System.in);

		//int a = sc.nextInt();
		//List<Integer> check=new ArrayList<Integer>();
		//array = new int[h+1][w+1];
		List<Integer> list=new ArrayList<Integer>();
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//Collections.reverse(list);
		List<Integer> list_two=new ArrayList<Integer>();

		int n = sc.nextInt();

		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list.add(a);
			list_two.add(a);
		}


		Collections.sort(list, Collections.reverseOrder());
		//System.out.println(list);
		//System.out.println(list_two);
		int list_in_max = Collections.max(list_two);
		int maxIndex = list_two.indexOf(Collections.max(list_two));
		//System.out.println(maxIndex);
		if(list.get(0).equals(list.get(1))) {
			for(int i=0;n>i;i++) {
				System.out.println(list_in_max);
			}
			System.exit(0);
		}

		else {
			for(int i=0;n>i;i++) {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			}

		}
		/*

		List<Integer> list_max=new ArrayList<Integer>();

		for(int i=0;n>i;i++) {
			int max =0;

			for(int j=0;n>j;j++) {
				if(i==j)
					continue;
				if(list.get(j)>max) {
					max = list.get(j);
				}

			}
			list_max.add(max);
		}

		for(int i=0;list_max.size()>i;i++) {
			System.out.println(list_max.get(i));
		}
		*/

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) List<Integer> list=new ArrayList<Integer>(); list new ArrayList<Integer>() List<Integer> list_two=new ArrayList<Integer>(); list_two new ArrayList<Integer>() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list.add(a);
			list_two.add(a);
		} int i=0; int i=0; i 0 n>i n i i++ i++ i {
			int a = sc.nextInt();
			list.add(a);
			list_two.add(a);
		} {
			int a = sc.nextInt();
			list.add(a);
			list_two.add(a);
		} int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc list.add(a) list.add list a list_two.add(a) list_two.add list_two a Collections.sort(list, Collections.reverseOrder()) Collections.sort Collections list Collections.reverseOrder() Collections.reverseOrder Collections int list_in_max = Collections.max(list_two); list_in_max Collections.max(list_two) Collections.max Collections list_two int maxIndex = list_two.indexOf(Collections.max(list_two)); maxIndex list_two.indexOf(Collections.max(list_two)) list_two.indexOf list_two Collections.max(list_two) Collections.max Collections list_two if(list.get(0).equals(list.get(1))) {
			for(int i=0;n>i;i++) {
				System.out.println(list_in_max);
			}
			System.exit(0);
		}

		else {
			for(int i=0;n>i;i++) {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			}

		} list.get(0).equals(list.get(1)) list.get(0).equals list.get(0) list.get list 0 list.get(1) list.get list 1 {
			for(int i=0;n>i;i++) {
				System.out.println(list_in_max);
			}
			System.exit(0);
		} for(int i=0;n>i;i++) {
				System.out.println(list_in_max);
			} int i=0; int i=0; i 0 n>i n i i++ i++ i {
				System.out.println(list_in_max);
			} {
				System.out.println(list_in_max);
			} System.out.println(list_in_max) System.out.println System.out System System.out list_in_max System.exit(0) System.exit System 0 {
			for(int i=0;n>i;i++) {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			}

		} for(int i=0;n>i;i++) {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			} int i=0; int i=0; i 0 n>i n i i++ i++ i {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			} {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			} if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				} i==maxIndex i maxIndex {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				} list_two.remove(i) list_two.remove list_two i System.out.println(Collections.max(list_two)) System.out.println System.out System System.out Collections.max(list_two) Collections.max Collections list_two {
					System.out.println(list_in_max);
				} System.out.println(list_in_max) System.out.println System.out System System.out list_in_max String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		//int a = sc.nextInt();
		//List<Integer> check=new ArrayList<Integer>();
		//array = new int[h+1][w+1];
		List<Integer> list=new ArrayList<Integer>();
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//Collections.reverse(list);
		List<Integer> list_two=new ArrayList<Integer>();

		int n = sc.nextInt();

		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list.add(a);
			list_two.add(a);
		}


		Collections.sort(list, Collections.reverseOrder());
		//System.out.println(list);
		//System.out.println(list_two);
		int list_in_max = Collections.max(list_two);
		int maxIndex = list_two.indexOf(Collections.max(list_two));
		//System.out.println(maxIndex);
		if(list.get(0).equals(list.get(1))) {
			for(int i=0;n>i;i++) {
				System.out.println(list_in_max);
			}
			System.exit(0);
		}

		else {
			for(int i=0;n>i;i++) {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			}

		}
		/*

		List<Integer> list_max=new ArrayList<Integer>();

		for(int i=0;n>i;i++) {
			int max =0;

			for(int j=0;n>j;j++) {
				if(i==j)
					continue;
				if(list.get(j)>max) {
					max = list.get(j);
				}

			}
			list_max.add(max);
		}

		for(int i=0;list_max.size()>i;i++) {
			System.out.println(list_max.get(i));
		}
		*/

	}

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

		//int a = sc.nextInt();
		//List<Integer> check=new ArrayList<Integer>();
		//array = new int[h+1][w+1];
		List<Integer> list=new ArrayList<Integer>();
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//Collections.reverse(list);
		List<Integer> list_two=new ArrayList<Integer>();

		int n = sc.nextInt();

		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list.add(a);
			list_two.add(a);
		}


		Collections.sort(list, Collections.reverseOrder());
		//System.out.println(list);
		//System.out.println(list_two);
		int list_in_max = Collections.max(list_two);
		int maxIndex = list_two.indexOf(Collections.max(list_two));
		//System.out.println(maxIndex);
		if(list.get(0).equals(list.get(1))) {
			for(int i=0;n>i;i++) {
				System.out.println(list_in_max);
			}
			System.exit(0);
		}

		else {
			for(int i=0;n>i;i++) {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			}

		}
		/*

		List<Integer> list_max=new ArrayList<Integer>();

		for(int i=0;n>i;i++) {
			int max =0;

			for(int j=0;n>j;j++) {
				if(i==j)
					continue;
				if(list.get(j)>max) {
					max = list.get(j);
				}

			}
			list_max.add(max);
		}

		for(int i=0;list_max.size()>i;i++) {
			System.out.println(list_max.get(i));
		}
		*/

	}

} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

		//int a = sc.nextInt();
		//List<Integer> check=new ArrayList<Integer>();
		//array = new int[h+1][w+1];
		List<Integer> list=new ArrayList<Integer>();
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//Collections.reverse(list);
		List<Integer> list_two=new ArrayList<Integer>();

		int n = sc.nextInt();

		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list.add(a);
			list_two.add(a);
		}


		Collections.sort(list, Collections.reverseOrder());
		//System.out.println(list);
		//System.out.println(list_two);
		int list_in_max = Collections.max(list_two);
		int maxIndex = list_two.indexOf(Collections.max(list_two));
		//System.out.println(maxIndex);
		if(list.get(0).equals(list.get(1))) {
			for(int i=0;n>i;i++) {
				System.out.println(list_in_max);
			}
			System.exit(0);
		}

		else {
			for(int i=0;n>i;i++) {
				if(i==maxIndex) {
					list_two.remove(i);
					System.out.println(Collections.max(list_two));
				}
				else {
					System.out.println(list_in_max);
				}
			}

		}
		/*

		List<Integer> list_max=new ArrayList<Integer>();

		for(int i=0;n>i;i++) {
			int max =0;

			for(int j=0;n>j;j++) {
				if(i==j)
					continue;
				if(list.get(j)>max) {
					max = list.get(j);
				}

			}
			list_max.add(max);
		}

		for(int i=0;list_max.size()>i;i++) {
			System.out.println(list_max.get(i));
		}
		*/

	}

}
