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

public class Main {
    private static final int MAX = Integer.MAX_VALUE;
    private static final int MIN = Integer.MIN_VALUE;

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);
        Scanner scanner = new Scanner(System.in);


        int n = in.nextInt();
        int [] a = new int[n];
        int maxIndex = 0;
        PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
            if(a[i] > a[maxIndex]) {
                maxIndex = i;
            }
            q.add(a[i]);
        }
        int secondMax = Integer.MIN_VALUE;
        int secondMaxIndex = 0;
        for (int i = 0; i < a.length; i++) {
            if(a[i] > secondMax && i!=maxIndex) {
                secondMax = a[i];
                secondMaxIndex = i;
            }
        }


        for (int i = 0; i < a.length; i++) {
            if(a[i] == a[maxIndex]) {
                out.println(a[secondMaxIndex]);
            }
            else {
                out.println(a[maxIndex]);
            }
        }
        out.flush();
    }
    static boolean isPrime(int n) {
        if(n<2) return false;
        for (int i = 2; i*i <=n ; i++) {
            if(n%i==0) return false;
        }
        return true;
    }

    static int min(char[][] c) {
        int [] row = new int[c.length];
        int [] col = new int[c[0].length];

        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            }
        }
        int ans = Integer.MAX_VALUE;
        int sum = c.length + c[0].length;
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            }
        }

        return ans;
    }
    static String solve(String s,String t, String p) {
        int [] main = freq(t);
        int [] sf = freq(s);
        int [] pf = freq(p);

        for (int i = 0; i < sf.length; i++) {
            if(sf[i] > main[i]) {
                return  "NO";
            }
        }
        for (int i = 0; i < sf.length; i++) {
            sf[i]+=pf[i];
        }
        for (int i = 0; i < sf.length; i++) {
            if(sf[i] < main[i]) {
                return "NO";
            }
        }
        int index = -1;
        for (char c : s.toCharArray()) {
            index = t.indexOf(c,index + 1);
            if(index < 0) {
                return "NO";
            }
        }
        return "YES";
    }
    private static int [] freq(String s) {
        int [] f = new int[26];
        for(char c : s.toCharArray()) {
            f[c-'a']++;
        }
        return f;
    }

}

class Point {
    int x;
    int y;
    public Point(int x,int y) {
        this.x = x;
        this.y = y;
    }
}

class Lift {

    int level;
    int time;

    public int getLevel() {
        return level;
    }

    public int getTime() {
        return time;
    }

    public Lift(int level, int time) {
        this.level = level;
        this.time = time;
    }
}

class InputReader extends BufferedReader {
    StringTokenizer tokenizer;

    public InputReader(InputStream inputStream) {
        super(new InputStreamReader(inputStream), 32768);
    }

    public InputReader(String filename) {
        super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return tokenizer.nextToken();
    }

    public Integer nextInt() {
        return Integer.valueOf(next());
    }
    public Long nextLong() {return  Long.valueOf(next());}

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    private static final int MAX = Integer.MAX_VALUE;
    private static final int MIN = Integer.MIN_VALUE;

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);
        Scanner scanner = new Scanner(System.in);


        int n = in.nextInt();
        int [] a = new int[n];
        int maxIndex = 0;
        PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
            if(a[i] > a[maxIndex]) {
                maxIndex = i;
            }
            q.add(a[i]);
        }
        int secondMax = Integer.MIN_VALUE;
        int secondMaxIndex = 0;
        for (int i = 0; i < a.length; i++) {
            if(a[i] > secondMax && i!=maxIndex) {
                secondMax = a[i];
                secondMaxIndex = i;
            }
        }


        for (int i = 0; i < a.length; i++) {
            if(a[i] == a[maxIndex]) {
                out.println(a[secondMaxIndex]);
            }
            else {
                out.println(a[maxIndex]);
            }
        }
        out.flush();
    }
    static boolean isPrime(int n) {
        if(n<2) return false;
        for (int i = 2; i*i <=n ; i++) {
            if(n%i==0) return false;
        }
        return true;
    }

    static int min(char[][] c) {
        int [] row = new int[c.length];
        int [] col = new int[c[0].length];

        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            }
        }
        int ans = Integer.MAX_VALUE;
        int sum = c.length + c[0].length;
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            }
        }

        return ans;
    }
    static String solve(String s,String t, String p) {
        int [] main = freq(t);
        int [] sf = freq(s);
        int [] pf = freq(p);

        for (int i = 0; i < sf.length; i++) {
            if(sf[i] > main[i]) {
                return  "NO";
            }
        }
        for (int i = 0; i < sf.length; i++) {
            sf[i]+=pf[i];
        }
        for (int i = 0; i < sf.length; i++) {
            if(sf[i] < main[i]) {
                return "NO";
            }
        }
        int index = -1;
        for (char c : s.toCharArray()) {
            index = t.indexOf(c,index + 1);
            if(index < 0) {
                return "NO";
            }
        }
        return "YES";
    }
    private static int [] freq(String s) {
        int [] f = new int[26];
        for(char c : s.toCharArray()) {
            f[c-'a']++;
        }
        return f;
    }

} Main private static final int MAX = Integer.MAX_VALUE; MAX Integer.MAX_VALUE Integer Integer.MAX_VALUE private static final int MIN = Integer.MIN_VALUE; MIN Integer.MIN_VALUE Integer Integer.MIN_VALUE public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);
        Scanner scanner = new Scanner(System.in);


        int n = in.nextInt();
        int [] a = new int[n];
        int maxIndex = 0;
        PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
            if(a[i] > a[maxIndex]) {
                maxIndex = i;
            }
            q.add(a[i]);
        }
        int secondMax = Integer.MIN_VALUE;
        int secondMaxIndex = 0;
        for (int i = 0; i < a.length; i++) {
            if(a[i] > secondMax && i!=maxIndex) {
                secondMax = a[i];
                secondMaxIndex = i;
            }
        }


        for (int i = 0; i < a.length; i++) {
            if(a[i] == a[maxIndex]) {
                out.println(a[secondMaxIndex]);
            }
            else {
                out.println(a[maxIndex]);
            }
        }
        out.flush();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);
        Scanner scanner = new Scanner(System.in);


        int n = in.nextInt();
        int [] a = new int[n];
        int maxIndex = 0;
        PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
            if(a[i] > a[maxIndex]) {
                maxIndex = i;
            }
            q.add(a[i]);
        }
        int secondMax = Integer.MIN_VALUE;
        int secondMaxIndex = 0;
        for (int i = 0; i < a.length; i++) {
            if(a[i] > secondMax && i!=maxIndex) {
                secondMax = a[i];
                secondMaxIndex = i;
            }
        }


        for (int i = 0; i < a.length; i++) {
            if(a[i] == a[maxIndex]) {
                out.println(a[secondMaxIndex]);
            }
            else {
                out.println(a[maxIndex]);
            }
        }
        out.flush();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out InputReader in = new InputReader(inputStream); in new InputReader(inputStream) InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream); out new InputReader.OutputWriter(outputStream) Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int [] a = new int[n]; a new int[n] n int maxIndex = 0; maxIndex 0 PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder()); q new PriorityQueue<>(Comparator.reverseOrder()) for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
            if(a[i] > a[maxIndex]) {
                maxIndex = i;
            }
            q.add(a[i]);
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
            a[i] = in.nextInt();
            if(a[i] > a[maxIndex]) {
                maxIndex = i;
            }
            q.add(a[i]);
        } {
            a[i] = in.nextInt();
            if(a[i] > a[maxIndex]) {
                maxIndex = i;
            }
            q.add(a[i]);
        } a[i] = in.nextInt() a[i] a i in.nextInt() in.nextInt in if(a[i] > a[maxIndex]) {
                maxIndex = i;
            } a[i] > a[maxIndex] a[i] a i a[maxIndex] a maxIndex {
                maxIndex = i;
            } maxIndex = i maxIndex i q.add(a[i]) q.add q a[i] a i int secondMax = Integer.MIN_VALUE; secondMax Integer.MIN_VALUE Integer Integer.MIN_VALUE int secondMaxIndex = 0; secondMaxIndex 0 for (int i = 0; i < a.length; i++) {
            if(a[i] > secondMax && i!=maxIndex) {
                secondMax = a[i];
                secondMaxIndex = i;
            }
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
            if(a[i] > secondMax && i!=maxIndex) {
                secondMax = a[i];
                secondMaxIndex = i;
            }
        } {
            if(a[i] > secondMax && i!=maxIndex) {
                secondMax = a[i];
                secondMaxIndex = i;
            }
        } if(a[i] > secondMax && i!=maxIndex) {
                secondMax = a[i];
                secondMaxIndex = i;
            } a[i] > secondMax && i!=maxIndex a[i] > secondMax a[i] a i secondMax i!=maxIndex i maxIndex {
                secondMax = a[i];
                secondMaxIndex = i;
            } secondMax = a[i] secondMax a[i] a i secondMaxIndex = i secondMaxIndex i for (int i = 0; i < a.length; i++) {
            if(a[i] == a[maxIndex]) {
                out.println(a[secondMaxIndex]);
            }
            else {
                out.println(a[maxIndex]);
            }
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
            if(a[i] == a[maxIndex]) {
                out.println(a[secondMaxIndex]);
            }
            else {
                out.println(a[maxIndex]);
            }
        } {
            if(a[i] == a[maxIndex]) {
                out.println(a[secondMaxIndex]);
            }
            else {
                out.println(a[maxIndex]);
            }
        } if(a[i] == a[maxIndex]) {
                out.println(a[secondMaxIndex]);
            }
            else {
                out.println(a[maxIndex]);
            } a[i] == a[maxIndex] a[i] a i a[maxIndex] a maxIndex {
                out.println(a[secondMaxIndex]);
            } out.println(a[secondMaxIndex]) out.println out a[secondMaxIndex] a secondMaxIndex {
                out.println(a[maxIndex]);
            } out.println(a[maxIndex]) out.println out a[maxIndex] a maxIndex out.flush() out.flush out String[] args args static boolean isPrime(int n) {
        if(n<2) return false;
        for (int i = 2; i*i <=n ; i++) {
            if(n%i==0) return false;
        }
        return true;
    } isPrime {
        if(n<2) return false;
        for (int i = 2; i*i <=n ; i++) {
            if(n%i==0) return false;
        }
        return true;
    } if(n<2) return false; n<2 n 2 return false; false for (int i = 2; i*i <=n ; i++) {
            if(n%i==0) return false;
        } int i = 2; int i = 2; i 2 i*i <=n i*i i i n i++ i++ i {
            if(n%i==0) return false;
        } {
            if(n%i==0) return false;
        } if(n%i==0) return false; n%i==0 n%i n i 0 return false; false return true; true int n n static int min(char[][] c) {
        int [] row = new int[c.length];
        int [] col = new int[c[0].length];

        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            }
        }
        int ans = Integer.MAX_VALUE;
        int sum = c.length + c[0].length;
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            }
        }

        return ans;
    } min {
        int [] row = new int[c.length];
        int [] col = new int[c[0].length];

        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            }
        }
        int ans = Integer.MAX_VALUE;
        int sum = c.length + c[0].length;
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            }
        }

        return ans;
    } int [] row = new int[c.length]; row new int[c.length] c.length c c.length int [] col = new int[c[0].length]; col new int[c[0].length] c[0].length c[0] c 0 c[0].length for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            }
        } int i = 0; int i = 0; i 0 i < c.length i c.length c c.length i++ i++ i {
            for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            }
        } {
            for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            }
        } for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            } int j = 0; int j = 0; j 0 j < c[0].length j c[0].length c[0] c 0 c[0].length j++ j++ j {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            } {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            } if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                } c[i][j] == '*' c[i][j] c[i] c i j '*' {
                    row[i]++;
                    col[j]++;
                } row[i]++ row[i] row i col[j]++ col[j] col j int ans = Integer.MAX_VALUE; ans Integer.MAX_VALUE Integer Integer.MAX_VALUE int sum = c.length + c[0].length; sum c.length + c[0].length c.length c c.length c[0].length c[0] c 0 c[0].length for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            }
        } int i = 0; int i = 0; i 0 i < c.length i c.length c c.length i++ i++ i {
            for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            }
        } {
            for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            }
        } for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            } int j = 0; int j = 0; j 0 j < c[0].length j c[0].length c[0] c 0 c[0].length j++ j++ j {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            } {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            } int count = sum -  row[i] - col[j]; count sum -  row[i] - col[j] sum -  row[i] - col[j] sum row[i] row i col[j] col j if(c[i][j] == '.') count--; c[i][j] == '.' c[i][j] c[i] c i j '.' count-- count ans = Math.min(ans,count) ans Math.min(ans,count) Math.min Math ans count return ans; ans char[][] c c static String solve(String s,String t, String p) {
        int [] main = freq(t);
        int [] sf = freq(s);
        int [] pf = freq(p);

        for (int i = 0; i < sf.length; i++) {
            if(sf[i] > main[i]) {
                return  "NO";
            }
        }
        for (int i = 0; i < sf.length; i++) {
            sf[i]+=pf[i];
        }
        for (int i = 0; i < sf.length; i++) {
            if(sf[i] < main[i]) {
                return "NO";
            }
        }
        int index = -1;
        for (char c : s.toCharArray()) {
            index = t.indexOf(c,index + 1);
            if(index < 0) {
                return "NO";
            }
        }
        return "YES";
    } solve {
        int [] main = freq(t);
        int [] sf = freq(s);
        int [] pf = freq(p);

        for (int i = 0; i < sf.length; i++) {
            if(sf[i] > main[i]) {
                return  "NO";
            }
        }
        for (int i = 0; i < sf.length; i++) {
            sf[i]+=pf[i];
        }
        for (int i = 0; i < sf.length; i++) {
            if(sf[i] < main[i]) {
                return "NO";
            }
        }
        int index = -1;
        for (char c : s.toCharArray()) {
            index = t.indexOf(c,index + 1);
            if(index < 0) {
                return "NO";
            }
        }
        return "YES";
    } int [] main = freq(t); main freq(t) freq t int [] sf = freq(s); sf freq(s) freq s int [] pf = freq(p); pf freq(p) freq p for (int i = 0; i < sf.length; i++) {
            if(sf[i] > main[i]) {
                return  "NO";
            }
        } int i = 0; int i = 0; i 0 i < sf.length i sf.length sf sf.length i++ i++ i {
            if(sf[i] > main[i]) {
                return  "NO";
            }
        } {
            if(sf[i] > main[i]) {
                return  "NO";
            }
        } if(sf[i] > main[i]) {
                return  "NO";
            } sf[i] > main[i] sf[i] sf i main[i] main i {
                return  "NO";
            } return  "NO"; "NO" for (int i = 0; i < sf.length; i++) {
            sf[i]+=pf[i];
        } int i = 0; int i = 0; i 0 i < sf.length i sf.length sf sf.length i++ i++ i {
            sf[i]+=pf[i];
        } {
            sf[i]+=pf[i];
        } sf[i]+=pf[i] sf[i] sf i pf[i] pf i for (int i = 0; i < sf.length; i++) {
            if(sf[i] < main[i]) {
                return "NO";
            }
        } int i = 0; int i = 0; i 0 i < sf.length i sf.length sf sf.length i++ i++ i {
            if(sf[i] < main[i]) {
                return "NO";
            }
        } {
            if(sf[i] < main[i]) {
                return "NO";
            }
        } if(sf[i] < main[i]) {
                return "NO";
            } sf[i] < main[i] sf[i] sf i main[i] main i {
                return "NO";
            } return "NO"; "NO" int index = -1; index -1 1 for (char c : s.toCharArray()) {
            index = t.indexOf(c,index + 1);
            if(index < 0) {
                return "NO";
            }
        } char c s.toCharArray() s.toCharArray s {
            index = t.indexOf(c,index + 1);
            if(index < 0) {
                return "NO";
            }
        } {
            index = t.indexOf(c,index + 1);
            if(index < 0) {
                return "NO";
            }
        } index = t.indexOf(c,index + 1) index t.indexOf(c,index + 1) t.indexOf t c index + 1 index 1 if(index < 0) {
                return "NO";
            } index < 0 index 0 {
                return "NO";
            } return "NO"; "NO" return "YES"; "YES" String s s String t t String p p private static int [] freq(String s) {
        int [] f = new int[26];
        for(char c : s.toCharArray()) {
            f[c-'a']++;
        }
        return f;
    } freq {
        int [] f = new int[26];
        for(char c : s.toCharArray()) {
            f[c-'a']++;
        }
        return f;
    } int [] f = new int[26]; f new int[26] 26 for(char c : s.toCharArray()) {
            f[c-'a']++;
        } char c s.toCharArray() s.toCharArray s {
            f[c-'a']++;
        } {
            f[c-'a']++;
        } f[c-'a']++ f[c-'a'] f c-'a' c 'a' return f; f String s s class Point {
    int x;
    int y;
    public Point(int x,int y) {
        this.x = x;
        this.y = y;
    }
} Point int x; x int y; y public Point(int x,int y) {
        this.x = x;
        this.y = y;
    } Point {
        this.x = x;
        this.y = y;
    } this.x = x this.x this this.x x this.y = y this.y this this.y y int x x int y y class Lift {

    int level;
    int time;

    public int getLevel() {
        return level;
    }

    public int getTime() {
        return time;
    }

    public Lift(int level, int time) {
        this.level = level;
        this.time = time;
    }
} Lift int level; level int time; time public int getLevel() {
        return level;
    } getLevel {
        return level;
    } return level; level public int getTime() {
        return time;
    } getTime {
        return time;
    } return time; time public Lift(int level, int time) {
        this.level = level;
        this.time = time;
    } Lift {
        this.level = level;
        this.time = time;
    } this.level = level this.level this this.level level this.time = time this.time this this.time time int level level int time time class InputReader extends BufferedReader {
    StringTokenizer tokenizer;

    public InputReader(InputStream inputStream) {
        super(new InputStreamReader(inputStream), 32768);
    }

    public InputReader(String filename) {
        super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return tokenizer.nextToken();
    }

    public Integer nextInt() {
        return Integer.valueOf(next());
    }
    public Long nextLong() {return  Long.valueOf(next());}

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }
    }
} InputReader StringTokenizer tokenizer; tokenizer public InputReader(InputStream inputStream) {
        super(new InputStreamReader(inputStream), 32768);
    } InputReader {
        super(new InputStreamReader(inputStream), 32768);
    } super(new InputStreamReader(inputStream), 32768) super new InputStreamReader(inputStream) 32768 InputStream inputStream inputStream public InputReader(String filename) {
        super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
    } InputReader {
        super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
    } super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename))) super new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)) String filename filename public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return tokenizer.nextToken();
    } next {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return tokenizer.nextToken();
    } while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        } try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            } catch (IOException e) {
                throw new RuntimeException();
            } IOException e {
                throw new RuntimeException();
            } throw new RuntimeException(); new RuntimeException() {
                tokenizer = new StringTokenizer(readLine());
            } tokenizer = new StringTokenizer(readLine()) tokenizer new StringTokenizer(readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public Integer nextInt() {
        return Integer.valueOf(next());
    } nextInt {
        return Integer.valueOf(next());
    } return Integer.valueOf(next()); Integer.valueOf(next()) Integer.valueOf Integer next() next public Long nextLong() {return  Long.valueOf(next());} nextLong {return  Long.valueOf(next());} return  Long.valueOf(next()); Long.valueOf(next()) Long.valueOf Long next() next static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }
    } OutputWriter public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        } OutputWriter {
            super(outputStream);
        } super(outputStream) super outputStream OutputStream outputStream outputStream public OutputWriter(Writer writer) {
            super(writer);
        } OutputWriter {
            super(writer);
        } super(writer) super writer Writer writer writer public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        } OutputWriter {
            super(filename);
        } super(filename) super filename String filename filename public void close() {
            super.close();
        } close {
            super.close();
        } super.close() super.close super PrintWriter BufferedReader public class Main {
    private static final int MAX = Integer.MAX_VALUE;
    private static final int MIN = Integer.MIN_VALUE;

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);
        Scanner scanner = new Scanner(System.in);


        int n = in.nextInt();
        int [] a = new int[n];
        int maxIndex = 0;
        PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
            if(a[i] > a[maxIndex]) {
                maxIndex = i;
            }
            q.add(a[i]);
        }
        int secondMax = Integer.MIN_VALUE;
        int secondMaxIndex = 0;
        for (int i = 0; i < a.length; i++) {
            if(a[i] > secondMax && i!=maxIndex) {
                secondMax = a[i];
                secondMaxIndex = i;
            }
        }


        for (int i = 0; i < a.length; i++) {
            if(a[i] == a[maxIndex]) {
                out.println(a[secondMaxIndex]);
            }
            else {
                out.println(a[maxIndex]);
            }
        }
        out.flush();
    }
    static boolean isPrime(int n) {
        if(n<2) return false;
        for (int i = 2; i*i <=n ; i++) {
            if(n%i==0) return false;
        }
        return true;
    }

    static int min(char[][] c) {
        int [] row = new int[c.length];
        int [] col = new int[c[0].length];

        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            }
        }
        int ans = Integer.MAX_VALUE;
        int sum = c.length + c[0].length;
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            }
        }

        return ans;
    }
    static String solve(String s,String t, String p) {
        int [] main = freq(t);
        int [] sf = freq(s);
        int [] pf = freq(p);

        for (int i = 0; i < sf.length; i++) {
            if(sf[i] > main[i]) {
                return  "NO";
            }
        }
        for (int i = 0; i < sf.length; i++) {
            sf[i]+=pf[i];
        }
        for (int i = 0; i < sf.length; i++) {
            if(sf[i] < main[i]) {
                return "NO";
            }
        }
        int index = -1;
        for (char c : s.toCharArray()) {
            index = t.indexOf(c,index + 1);
            if(index < 0) {
                return "NO";
            }
        }
        return "YES";
    }
    private static int [] freq(String s) {
        int [] f = new int[26];
        for(char c : s.toCharArray()) {
            f[c-'a']++;
        }
        return f;
    }

} public class Main {
    private static final int MAX = Integer.MAX_VALUE;
    private static final int MIN = Integer.MIN_VALUE;

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);
        Scanner scanner = new Scanner(System.in);


        int n = in.nextInt();
        int [] a = new int[n];
        int maxIndex = 0;
        PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
            if(a[i] > a[maxIndex]) {
                maxIndex = i;
            }
            q.add(a[i]);
        }
        int secondMax = Integer.MIN_VALUE;
        int secondMaxIndex = 0;
        for (int i = 0; i < a.length; i++) {
            if(a[i] > secondMax && i!=maxIndex) {
                secondMax = a[i];
                secondMaxIndex = i;
            }
        }


        for (int i = 0; i < a.length; i++) {
            if(a[i] == a[maxIndex]) {
                out.println(a[secondMaxIndex]);
            }
            else {
                out.println(a[maxIndex]);
            }
        }
        out.flush();
    }
    static boolean isPrime(int n) {
        if(n<2) return false;
        for (int i = 2; i*i <=n ; i++) {
            if(n%i==0) return false;
        }
        return true;
    }

    static int min(char[][] c) {
        int [] row = new int[c.length];
        int [] col = new int[c[0].length];

        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            }
        }
        int ans = Integer.MAX_VALUE;
        int sum = c.length + c[0].length;
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            }
        }

        return ans;
    }
    static String solve(String s,String t, String p) {
        int [] main = freq(t);
        int [] sf = freq(s);
        int [] pf = freq(p);

        for (int i = 0; i < sf.length; i++) {
            if(sf[i] > main[i]) {
                return  "NO";
            }
        }
        for (int i = 0; i < sf.length; i++) {
            sf[i]+=pf[i];
        }
        for (int i = 0; i < sf.length; i++) {
            if(sf[i] < main[i]) {
                return "NO";
            }
        }
        int index = -1;
        for (char c : s.toCharArray()) {
            index = t.indexOf(c,index + 1);
            if(index < 0) {
                return "NO";
            }
        }
        return "YES";
    }
    private static int [] freq(String s) {
        int [] f = new int[26];
        for(char c : s.toCharArray()) {
            f[c-'a']++;
        }
        return f;
    }

} Main
import java.io.*;
import java.util.*;

public class Main {
    private static final int MAX = Integer.MAX_VALUE;
    private static final int MIN = Integer.MIN_VALUE;

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);
        Scanner scanner = new Scanner(System.in);


        int n = in.nextInt();
        int [] a = new int[n];
        int maxIndex = 0;
        PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
            if(a[i] > a[maxIndex]) {
                maxIndex = i;
            }
            q.add(a[i]);
        }
        int secondMax = Integer.MIN_VALUE;
        int secondMaxIndex = 0;
        for (int i = 0; i < a.length; i++) {
            if(a[i] > secondMax && i!=maxIndex) {
                secondMax = a[i];
                secondMaxIndex = i;
            }
        }


        for (int i = 0; i < a.length; i++) {
            if(a[i] == a[maxIndex]) {
                out.println(a[secondMaxIndex]);
            }
            else {
                out.println(a[maxIndex]);
            }
        }
        out.flush();
    }
    static boolean isPrime(int n) {
        if(n<2) return false;
        for (int i = 2; i*i <=n ; i++) {
            if(n%i==0) return false;
        }
        return true;
    }

    static int min(char[][] c) {
        int [] row = new int[c.length];
        int [] col = new int[c[0].length];

        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            }
        }
        int ans = Integer.MAX_VALUE;
        int sum = c.length + c[0].length;
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            }
        }

        return ans;
    }
    static String solve(String s,String t, String p) {
        int [] main = freq(t);
        int [] sf = freq(s);
        int [] pf = freq(p);

        for (int i = 0; i < sf.length; i++) {
            if(sf[i] > main[i]) {
                return  "NO";
            }
        }
        for (int i = 0; i < sf.length; i++) {
            sf[i]+=pf[i];
        }
        for (int i = 0; i < sf.length; i++) {
            if(sf[i] < main[i]) {
                return "NO";
            }
        }
        int index = -1;
        for (char c : s.toCharArray()) {
            index = t.indexOf(c,index + 1);
            if(index < 0) {
                return "NO";
            }
        }
        return "YES";
    }
    private static int [] freq(String s) {
        int [] f = new int[26];
        for(char c : s.toCharArray()) {
            f[c-'a']++;
        }
        return f;
    }

}

class Point {
    int x;
    int y;
    public Point(int x,int y) {
        this.x = x;
        this.y = y;
    }
}

class Lift {

    int level;
    int time;

    public int getLevel() {
        return level;
    }

    public int getTime() {
        return time;
    }

    public Lift(int level, int time) {
        this.level = level;
        this.time = time;
    }
}

class InputReader extends BufferedReader {
    StringTokenizer tokenizer;

    public InputReader(InputStream inputStream) {
        super(new InputStreamReader(inputStream), 32768);
    }

    public InputReader(String filename) {
        super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return tokenizer.nextToken();
    }

    public Integer nextInt() {
        return Integer.valueOf(next());
    }
    public Long nextLong() {return  Long.valueOf(next());}

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }
    }
}