#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  int maxi = 0;
  for (int i = 0; i < N; i++) {
    maxi = max(maxi, a.at(i));
  }
  for (int i = 0; i < N; i++) {
    if (maxi == a.at(i)) {
      int b, c;
      b = 0;
      c = 0;
      for (int j = 0; j < i; j++) {
        b = max(b, a.at(j));
      }
      for (int j = i + 1; j < N; j++) {
        c = max(c, a.at(j));
      }
      cout << max(b, c) << endl;
    } else
      cout << maxi << endl;
  }
}
