import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.List;

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int input[]=new int[n];
        for (int i=0;i<n;i++){
            int x=sc.nextInt();
            input[i]=x;
        }
        int max=-1;
        int max2=-1;
        for (int i=0;i<n;i++){
            if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            }
        }
        for (int i:input){
            if (i==max) System.out.println(max2);
            else System.out.println(max);
        }



    }

}
 import java.awt.*; awt.* java import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.*; util.* java import java.util.List; List java.util public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int input[]=new int[n];
        for (int i=0;i<n;i++){
            int x=sc.nextInt();
            input[i]=x;
        }
        int max=-1;
        int max2=-1;
        for (int i=0;i<n;i++){
            if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            }
        }
        for (int i:input){
            if (i==max) System.out.println(max2);
            else System.out.println(max);
        }



    }

} Main public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int input[]=new int[n];
        for (int i=0;i<n;i++){
            int x=sc.nextInt();
            input[i]=x;
        }
        int max=-1;
        int max2=-1;
        for (int i=0;i<n;i++){
            if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            }
        }
        for (int i:input){
            if (i==max) System.out.println(max2);
            else System.out.println(max);
        }



    } main {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int input[]=new int[n];
        for (int i=0;i<n;i++){
            int x=sc.nextInt();
            input[i]=x;
        }
        int max=-1;
        int max2=-1;
        for (int i=0;i<n;i++){
            if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            }
        }
        for (int i:input){
            if (i==max) System.out.println(max2);
            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 input[]=new int[n]; input new int[n] n for (int i=0;i<n;i++){
            int x=sc.nextInt();
            input[i]=x;
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            int x=sc.nextInt();
            input[i]=x;
        } {
            int x=sc.nextInt();
            input[i]=x;
        } int x=sc.nextInt(); x sc.nextInt() sc.nextInt sc input[i]=x input[i] input i x int max=-1; max -1 1 int max2=-1; max2 -1 1 for (int i=0;i<n;i++){
            if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            }
        } {
            if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            }
        } if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            } input[i]>=max input[i] input i max {
                max2=max;
                max=input[i];
            } max2=max max2 max max=input[i] max input[i] input i if (input[i]>=max2){
                max2=input[i];
            } input[i]>=max2 input[i] input i max2 {
                max2=input[i];
            } max2=input[i] max2 input[i] input i for (int i:input){
            if (i==max) System.out.println(max2);
            else System.out.println(max);
        } int i input {
            if (i==max) System.out.println(max2);
            else System.out.println(max);
        } {
            if (i==max) System.out.println(max2);
            else System.out.println(max);
        } if (i==max) System.out.println(max2);
            else System.out.println(max); i==max i max System.out.println(max2) System.out.println System.out System System.out max2 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[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int input[]=new int[n];
        for (int i=0;i<n;i++){
            int x=sc.nextInt();
            input[i]=x;
        }
        int max=-1;
        int max2=-1;
        for (int i=0;i<n;i++){
            if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            }
        }
        for (int i:input){
            if (i==max) System.out.println(max2);
            else System.out.println(max);
        }



    }

} public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int input[]=new int[n];
        for (int i=0;i<n;i++){
            int x=sc.nextInt();
            input[i]=x;
        }
        int max=-1;
        int max2=-1;
        for (int i=0;i<n;i++){
            if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            }
        }
        for (int i:input){
            if (i==max) System.out.println(max2);
            else System.out.println(max);
        }



    }

} Main
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.List;

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int input[]=new int[n];
        for (int i=0;i<n;i++){
            int x=sc.nextInt();
            input[i]=x;
        }
        int max=-1;
        int max2=-1;
        for (int i=0;i<n;i++){
            if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            }
        }
        for (int i:input){
            if (i==max) System.out.println(max2);
            else System.out.println(max);
        }



    }

}

