#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, maxv = -1, maxv1 = -1, memo, maxi;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    maxv = max(maxv, a[i]);
    if (maxv != memo) {
      maxi = i;
    }
    memo = maxv;
  }
  for (int i = 0; i < n; i++) {
    cout << maxv << endl;
    if (maxi == i) {
      for (int j = 0; j < n; j++) {
        if (i == j) {
          continue;
        }
        maxv1 = max(maxv1, a[j]);
      }
      cout << maxv1 << endl;
    }
  }
}
