#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  set<ll> B;
  ll tmp = 0;
  for (int(i) = 0, i_len = (N); (i) < (i_len); ++(i)) {
    cin >> A[i];
    tmp = (((tmp) > (A[i])) ? (tmp) : (A[i]));
    B.insert(A[i]);
  }
  auto itr = B.end();
  --itr;
  for (int(i) = 0, i_len = (N); (i) < (i_len); ++(i)) {
    if (A[i] == tmp) {
      --itr;
      cout << *itr << endl;
      ++itr;
    } else
      cout << tmp << endl;
  }
  return 0;
}
