#include <bits/stdc++.h>
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long, long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long, long>>;
int main() {
  int N;
  cin >> N;
  vector<P> A(N);
  for (int i = 0; i < (N); ++i) {
    int a;
    cin >> a;
    A.at(i).first = a;
    A.at(i).second = i;
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  for (int i = 0; i < (N); ++i) {
    if (A.at(0).second == i)
      cout << A.at(0).first << endl;
    else
      cout << A.at(1).first << endl;
  }
}
