#include <bits/stdc++.h>
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;
void solve() {
  int N;
  cin >> N;
  vector<int> v(N);
  int max = 0;
  int prev = 0;
  for (int &x : v) {
    cin >> x;
    if (max <= x) {
      prev = max;
      max = x;
    }
  }
  for (int i = 0; i < N; i++) {
    if (v[i] == max) {
      cout << prev << endl;
    } else {
      cout << max << endl;
    }
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
