#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int max_num = *max_element(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    if (a[i] != max_num) {
      cout << max_num << '\n';
    } else {
      if (i != 0 && i != n - 1) {
        cout << max(*max_element(a.begin(), a.begin() + i - 1),
                    *max_element(a.begin() + i + 1, a.end()))
             << '\n';
      } else if (i == n - 1) {
        cout << *max_element(a.begin(), a.end() - 1) << '\n';
      } else {
        cout << *max_element(a.begin() + 1, a.end()) << '\n';
      }
    }
  }
}
