#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  map<long long, long long> values;
  for (int i = 0; i < n; i++) {
    long long value;
    cin >> value;
    values.insert(make_pair(i, value));
  }
  typedef function<bool(pair<long long, long long>, pair<long long, long long>)>
      Comparator;
  Comparator compFunctor = [](pair<long long, long long> elem1,
                              pair<long long, long long> elem2) {
    return elem1.second < elem2.second;
  };
  set<pair<long long, long long>, Comparator> setofvalue(
      values.begin(), values.end(), compFunctor);
  for (int i = 0; i < n; i++) {
    if ((*(setofvalue.rbegin())).first == i) {
      cout << (*(++setofvalue.rbegin())).second << endl;
    } else {
      cout << (*(setofvalue.rbegin())).second << endl;
    }
  }
}
