import 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];
		int max=0;
		int sec=0;
		for(int i=0;i<a.length;i++){
			a[i]=sc.nextInt();
			if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			}
		}
				
		for(int i=0;i<a.length;i++){
			if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			}

		}	
	}

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

		int[] a=new int[N];
		int max=0;
		int sec=0;
		for(int i=0;i<a.length;i++){
			a[i]=sc.nextInt();
			if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			}
		}
				
		for(int i=0;i<a.length;i++){
			if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			}

		}	
	}

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

		int[] a=new int[N];
		int max=0;
		int sec=0;
		for(int i=0;i<a.length;i++){
			a[i]=sc.nextInt();
			if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			}
		}
				
		for(int i=0;i<a.length;i++){
			if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			}

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

		int[] a=new int[N];
		int max=0;
		int sec=0;
		for(int i=0;i<a.length;i++){
			a[i]=sc.nextInt();
			if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			}
		}
				
		for(int i=0;i<a.length;i++){
			if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			}

		}	
	} 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 int max=0; max 0 int sec=0; sec 0 for(int i=0;i<a.length;i++){
			a[i]=sc.nextInt();
			if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			}
		} int i=0; int i=0; i 0 i<a.length i a.length a a.length i++ i++ i {
			a[i]=sc.nextInt();
			if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			}
		} {
			a[i]=sc.nextInt();
			if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			}
		} a[i]=sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			} a[i]>max a[i] a i max {
				sec=max;
				max=a[i];
			} sec=max sec max max=a[i] max a[i] a i if(a[i]>sec){
				sec=a[i];
			} a[i]>sec a[i] a i sec {
				sec=a[i];
			} sec=a[i] sec a[i] a i for(int i=0;i<a.length;i++){
			if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			}

		} int i=0; int i=0; i 0 i<a.length i a.length a a.length i++ i++ i {
			if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			}

		} {
			if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			}

		} if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			} a[i]==max a[i] a i max {
				System.out.println(sec);
			} System.out.println(sec) System.out.println System.out System System.out sec {
				System.out.println(max);
			} System.out.println(max) System.out.println System.out System System.out max 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];
		int max=0;
		int sec=0;
		for(int i=0;i<a.length;i++){
			a[i]=sc.nextInt();
			if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			}
		}
				
		for(int i=0;i<a.length;i++){
			if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			}

		}	
	}

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

		int[] a=new int[N];
		int max=0;
		int sec=0;
		for(int i=0;i<a.length;i++){
			a[i]=sc.nextInt();
			if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			}
		}
				
		for(int i=0;i<a.length;i++){
			if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			}

		}	
	}

} Main
import 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];
		int max=0;
		int sec=0;
		for(int i=0;i<a.length;i++){
			a[i]=sc.nextInt();
			if(a[i]>max){
				sec=max;
				max=a[i];
			}else if(a[i]>sec){
				sec=a[i];
			}
		}
				
		for(int i=0;i<a.length;i++){
			if(a[i]==max){
				System.out.println(sec);
			}else{
				System.out.println(max);
			}

		}	
	}

}	