#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;
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
long long gcd(long long a, long long b);
long long lcm(long long x, long long y);
vector<long long> h;
vector<long long> ans;
set<long long> s;
map<long long, long long> m;
int main() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    h.push_back(tmp);
    s.insert(tmp);
    ans.push_back(0);
  }
  long long m0 = 0;
  long long m1 = 0;
  for (set<long long>::iterator it = s.begin(); it != s.end(); it++) {
    if (*it > m0) {
      m0 = *it;
    }
  }
  s.erase(m0);
  if (s.size() != 0) {
    for (set<long long>::iterator it = s.begin(); it != s.end(); it++) {
      if (*it > m1) {
        m1 = *it;
      }
    }
  } else {
    m1 = m0;
  }
  for (int i = 0; i < n; i++) {
    if (h[i] == m0) {
      ans[i] = m1;
    } else {
      ans[i] = m0;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
