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

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] A = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                A[i] = sc.nextLong();
        }

        final Solver solver = new Solver();
        solver.solve(N, A);
    }
}

class Solver {
    public void solve(long N, long[] A) {
        long largest = 0;
        int largestIndex = 0;
        long secondLargest = 0;

        for (int i = 0; i < N; i++) {
            long v = A[i];

            if (largest < v) {
                largest = v;
                largestIndex = i;
                continue;
            }

            if (secondLargest < v) {
                secondLargest = v;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == largestIndex) {
                System.out.println(secondLargest);
            }
            else {
                System.out.println(largest);
            }
        }
    }
}
 import java.io.*; io.* java import java.util.*; util.* java public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] A = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                A[i] = sc.nextLong();
        }

        final Solver solver = new Solver();
        solver.solve(N, A);
    }
} Main public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] A = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                A[i] = sc.nextLong();
        }

        final Solver solver = new Solver();
        solver.solve(N, A);
    } main {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] A = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                A[i] = sc.nextLong();
        }

        final Solver solver = new Solver();
        solver.solve(N, A);
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long N; N N = sc.nextLong() N sc.nextLong() sc.nextLong sc long[] A = new long[(int)(N)]; A new long[(int)(N)] (int)(N) for(int i = 0 ; i < N ; i++){
                A[i] = sc.nextLong();
        } int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
                A[i] = sc.nextLong();
        } {
                A[i] = sc.nextLong();
        } A[i] = sc.nextLong() A[i] A i sc.nextLong() sc.nextLong sc final Solver solver = new Solver(); solver new Solver() solver.solve(N, A) solver.solve solver N A final String[] args args class Solver {
    public void solve(long N, long[] A) {
        long largest = 0;
        int largestIndex = 0;
        long secondLargest = 0;

        for (int i = 0; i < N; i++) {
            long v = A[i];

            if (largest < v) {
                largest = v;
                largestIndex = i;
                continue;
            }

            if (secondLargest < v) {
                secondLargest = v;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == largestIndex) {
                System.out.println(secondLargest);
            }
            else {
                System.out.println(largest);
            }
        }
    }
} Solver public void solve(long N, long[] A) {
        long largest = 0;
        int largestIndex = 0;
        long secondLargest = 0;

        for (int i = 0; i < N; i++) {
            long v = A[i];

            if (largest < v) {
                largest = v;
                largestIndex = i;
                continue;
            }

            if (secondLargest < v) {
                secondLargest = v;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == largestIndex) {
                System.out.println(secondLargest);
            }
            else {
                System.out.println(largest);
            }
        }
    } solve {
        long largest = 0;
        int largestIndex = 0;
        long secondLargest = 0;

        for (int i = 0; i < N; i++) {
            long v = A[i];

            if (largest < v) {
                largest = v;
                largestIndex = i;
                continue;
            }

            if (secondLargest < v) {
                secondLargest = v;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == largestIndex) {
                System.out.println(secondLargest);
            }
            else {
                System.out.println(largest);
            }
        }
    } long largest = 0; largest 0 int largestIndex = 0; largestIndex 0 long secondLargest = 0; secondLargest 0 for (int i = 0; i < N; i++) {
            long v = A[i];

            if (largest < v) {
                largest = v;
                largestIndex = i;
                continue;
            }

            if (secondLargest < v) {
                secondLargest = v;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            long v = A[i];

            if (largest < v) {
                largest = v;
                largestIndex = i;
                continue;
            }

            if (secondLargest < v) {
                secondLargest = v;
            }
        } {
            long v = A[i];

            if (largest < v) {
                largest = v;
                largestIndex = i;
                continue;
            }

            if (secondLargest < v) {
                secondLargest = v;
            }
        } long v = A[i]; v A[i] A i if (largest < v) {
                largest = v;
                largestIndex = i;
                continue;
            } largest < v largest v {
                largest = v;
                largestIndex = i;
                continue;
            } largest = v largest v largestIndex = i largestIndex i continue; if (secondLargest < v) {
                secondLargest = v;
            } secondLargest < v secondLargest v {
                secondLargest = v;
            } secondLargest = v secondLargest v for (int i = 0; i < N; i++) {
            if (i == largestIndex) {
                System.out.println(secondLargest);
            }
            else {
                System.out.println(largest);
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (i == largestIndex) {
                System.out.println(secondLargest);
            }
            else {
                System.out.println(largest);
            }
        } {
            if (i == largestIndex) {
                System.out.println(secondLargest);
            }
            else {
                System.out.println(largest);
            }
        } if (i == largestIndex) {
                System.out.println(secondLargest);
            }
            else {
                System.out.println(largest);
            } i == largestIndex i largestIndex {
                System.out.println(secondLargest);
            } System.out.println(secondLargest) System.out.println System.out System System.out secondLargest {
                System.out.println(largest);
            } System.out.println(largest) System.out.println System.out System System.out largest long N N long[] A A public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] A = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                A[i] = sc.nextLong();
        }

        final Solver solver = new Solver();
        solver.solve(N, A);
    }
} public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] A = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                A[i] = sc.nextLong();
        }

        final Solver solver = new Solver();
        solver.solve(N, A);
    }
} Main
import java.io.*;
import java.util.*;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] A = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                A[i] = sc.nextLong();
        }

        final Solver solver = new Solver();
        solver.solve(N, A);
    }
}

class Solver {
    public void solve(long N, long[] A) {
        long largest = 0;
        int largestIndex = 0;
        long secondLargest = 0;

        for (int i = 0; i < N; i++) {
            long v = A[i];

            if (largest < v) {
                largest = v;
                largestIndex = i;
                continue;
            }

            if (secondLargest < v) {
                secondLargest = v;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i == largestIndex) {
                System.out.println(secondLargest);
            }
            else {
                System.out.println(largest);
            }
        }
    }
}

