using System;

class Program
{
    static void Main(string[] args) {
        String ret;
        ret = process(new System.IO.StreamReader(Console.OpenStandardInput()));

        Console.WriteLine(ret);
        Console.ReadLine();
    }

    static string process(System.IO.TextReader input) {
        int n   = int.Parse(input.ReadLine());
        int[] a = new int[n];

        string ret = "";

        int max = 0;
        int second = 0;

        for(int i=0; i<n; i++) {
            a[i] = int.Parse(input.ReadLine());
            if(max < a[i]) {
                second = max;
                max = a[i];
            }else if(second < a[i]) {
                second = a[i];
            }
        }
        
        for(int i=0; i<n; i++) {
            if(a[i] == max) {
                ret += second + "\n";
            } else {
                ret += max + "\n";
            }
        }
        return ret;
    }

    static string process(string input) {
        return process(new System.IO.StringReader(input));
    }
}