#include <bits/stdc++.h>
using namespace std;
long long pow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res *= a;
    b /= 2;
    a *= a;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  multiset<int> ml;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    ml.insert(v[i]);
  }
  for (int i = 0; i < n; i++) {
    ml.erase(v[i]);
    auto it = ml.rbegin();
    cout << *it << "\n";
    ml.insert(v[i]);
  }
  return 0;
}
