#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    freopen("prizes.in", "rt", stdin);
    freopen("prizes.out", "wt", stdout);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int first_max = a[0];
    int second_max = a[1];
    if (a[0] < a[1])
        swap(first_max, second_max);
    cout << second_max << ' ';
    for (int i = 2; i < n; i++)
    {
        if (a[i] > first_max)
        {
            second_max = first_max;
            first_max = a[i];
        } 
        else if (a[i] > second_max) 
        {
            second_max = a[i];
        }
        cout << second_max << ' ';
    }
    return 0;
}