#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main(void) {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> w(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> v[i];
    w[i] = v[i];
  }
  sort(v.begin(), v.end(), greater<int>());
  int high, secondhigh;
  high = secondhigh = v[0];
  for (int i = 0; i < (int)(n); i++) {
    if (secondhigh != v[i]) {
      secondhigh = v[i];
      break;
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    if (w[i] == high)
      cout << secondhigh << endl;
    else
      cout << high << endl;
  }
  return 0;
}
