#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int> > A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i].first;
        A[i].second = i;
    }

    sort(A.begin(), A.end(), greater<int>());

    for (int i = 0; i < n; i++) {
        if (A[i].second == i)
            cout << A[1].first;
        else
            cout << A[0].first;
    }

    return 0;
}