#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
template <class T, class U>
inline bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U>
inline bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const ll inf = 1000000001;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < (n); ++i) {
    int b;
    cin >> b;
    a.push_back(b);
  }
  int max = *max_element((a).begin(), (a).end());
  int sec_max = 0;
  for (int i = 0; i < (n); ++i)
    if (sec_max < a[i] && a[i] != max) sec_max = a[i];
  for (int i = 0; i < (n); ++i) {
    if (a[i] != max)
      cout << max << ln;
    else
      cout << sec_max << ln;
  }
  return 0;
}
