#include "bits/stdc++.h"
#define puba push_back
#define mapa make_pair
#define ff first
#define ss second
#define bend(_x) (_x).begin(), (_x).end()
#define szof(_x) ((int) (_x).size())
#define TASK_NAME "prizes"

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

int n;
int m1, m2;

int main() {        
    freopen(TASK_NAME ".in", "r", stdin);
    freopen(TASK_NAME ".out", "w", stdout);

    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        int num;
        scanf("%d", &num);
        if (num > m2) {
            m1 = m2;
            m2 = num;
        } else if (num > m1) {
            m1 = num;
        }
        if (i) {
            cout << m1 << " ";
        }
    }
    cout << endl;

    return 0;
}