import java.io.PrintWriter;
import java.util.*;

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    final long mod = 1000000000+7;
    ArrayList<Integer>[] tree;
    long ans = 1;
    int n,k;
    public static void main(String[] args) {
        Main main = new Main();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = sc.nextInt();
        int maxVal = -1, maxKey = -1;
        for(int i=0;i<n;i++){
            if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            }
        }
        int secondVal = -1;
        for(int i=0;i<n;i++){
            if(i==maxKey) continue;
            secondVal = Math.max(a[i],secondVal);
        }
        for(int i=0;i<n;i++){
            if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal);
        }
        out.flush();
        System.exit(0);
        return 0;
    }
} import java.io.PrintWriter; PrintWriter java.io import java.util.*; util.* java public class Main {
    PrintWriter out = new PrintWriter(System.out);
    final long mod = 1000000000+7;
    ArrayList<Integer>[] tree;
    long ans = 1;
    int n,k;
    public static void main(String[] args) {
        Main main = new Main();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = sc.nextInt();
        int maxVal = -1, maxKey = -1;
        for(int i=0;i<n;i++){
            if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            }
        }
        int secondVal = -1;
        for(int i=0;i<n;i++){
            if(i==maxKey) continue;
            secondVal = Math.max(a[i],secondVal);
        }
        for(int i=0;i<n;i++){
            if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal);
        }
        out.flush();
        System.exit(0);
        return 0;
    }
} Main PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) final long mod = 1000000000+7; mod 1000000000+7 1000000000 7 ArrayList<Integer>[] tree; tree long ans = 1; ans 1 int n n k; k public static void main(String[] args) {
        Main main = new Main();
        System.out.println(main.solve());
    } main {
        Main main = new Main();
        System.out.println(main.solve());
    } Main main = new Main(); main new Main() System.out.println(main.solve()) System.out.println System.out System System.out main.solve() main.solve main String[] args args long solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = sc.nextInt();
        int maxVal = -1, maxKey = -1;
        for(int i=0;i<n;i++){
            if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            }
        }
        int secondVal = -1;
        for(int i=0;i<n;i++){
            if(i==maxKey) continue;
            secondVal = Math.max(a[i],secondVal);
        }
        for(int i=0;i<n;i++){
            if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal);
        }
        out.flush();
        System.exit(0);
        return 0;
    } solve {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = sc.nextInt();
        int maxVal = -1, maxKey = -1;
        for(int i=0;i<n;i++){
            if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            }
        }
        int secondVal = -1;
        for(int i=0;i<n;i++){
            if(i==maxKey) continue;
            secondVal = Math.max(a[i],secondVal);
        }
        for(int i=0;i<n;i++){
            if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal);
        }
        out.flush();
        System.exit(0);
        return 0;
    } 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 for(int i=0;i<n;i++) a[i] = sc.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i a[i] = sc.nextInt(); a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int maxVal = -1 maxVal -1 1 maxKey = -1; maxKey -1 1 for(int i=0;i<n;i++){
            if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            }
        } {
            if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            }
        } if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            } a[i]>maxVal a[i] a i maxVal {
                maxVal = a[i];
                maxKey = i;
            } maxVal = a[i] maxVal a[i] a i maxKey = i maxKey i int secondVal = -1; secondVal -1 1 for(int i=0;i<n;i++){
            if(i==maxKey) continue;
            secondVal = Math.max(a[i],secondVal);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if(i==maxKey) continue;
            secondVal = Math.max(a[i],secondVal);
        } {
            if(i==maxKey) continue;
            secondVal = Math.max(a[i],secondVal);
        } if(i==maxKey) continue; i==maxKey i maxKey continue; secondVal = Math.max(a[i],secondVal) secondVal Math.max(a[i],secondVal) Math.max Math a[i] a i secondVal for(int i=0;i<n;i++){
            if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal);
        } {
            if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal);
        } if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal); i!=maxKey i maxKey out.println(maxVal) out.println out maxVal out.println(secondVal) out.println out secondVal out.flush() out.flush out System.exit(0) System.exit System 0 return 0; 0 public class Main {
    PrintWriter out = new PrintWriter(System.out);
    final long mod = 1000000000+7;
    ArrayList<Integer>[] tree;
    long ans = 1;
    int n,k;
    public static void main(String[] args) {
        Main main = new Main();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = sc.nextInt();
        int maxVal = -1, maxKey = -1;
        for(int i=0;i<n;i++){
            if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            }
        }
        int secondVal = -1;
        for(int i=0;i<n;i++){
            if(i==maxKey) continue;
            secondVal = Math.max(a[i],secondVal);
        }
        for(int i=0;i<n;i++){
            if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal);
        }
        out.flush();
        System.exit(0);
        return 0;
    }
} public class Main {
    PrintWriter out = new PrintWriter(System.out);
    final long mod = 1000000000+7;
    ArrayList<Integer>[] tree;
    long ans = 1;
    int n,k;
    public static void main(String[] args) {
        Main main = new Main();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = sc.nextInt();
        int maxVal = -1, maxKey = -1;
        for(int i=0;i<n;i++){
            if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            }
        }
        int secondVal = -1;
        for(int i=0;i<n;i++){
            if(i==maxKey) continue;
            secondVal = Math.max(a[i],secondVal);
        }
        for(int i=0;i<n;i++){
            if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal);
        }
        out.flush();
        System.exit(0);
        return 0;
    }
} Main
import java.io.PrintWriter;
import java.util.*;

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    final long mod = 1000000000+7;
    ArrayList<Integer>[] tree;
    long ans = 1;
    int n,k;
    public static void main(String[] args) {
        Main main = new Main();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = sc.nextInt();
        int maxVal = -1, maxKey = -1;
        for(int i=0;i<n;i++){
            if(a[i]>maxVal){
                maxVal = a[i];
                maxKey = i;
            }
        }
        int secondVal = -1;
        for(int i=0;i<n;i++){
            if(i==maxKey) continue;
            secondVal = Math.max(a[i],secondVal);
        }
        for(int i=0;i<n;i++){
            if(i!=maxKey) out.println(maxVal);
            else out.println(secondVal);
        }
        out.flush();
        System.exit(0);
        return 0;
    }
}