#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  const ll mod = 1e9;
  ll n;
  cin >> n;
  multiset<ll> s;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    s.insert(a[i]);
  }
  for (ll i = 0; i < n; i++) {
    s.erase(s.find(a[i]));
    cout << *s.rend() << '\n';
    s.insert(a[i]);
  }
  return 0;
}
