#include <bits/stdc++.h>
using namespace std;
template <typename X>
bool exist(vector<X> vec, X item) {
  return find(vec.begin(), vec.end(), item) != vec.end();
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long power(long long x, long long n) {
  if (n == 0) return 1;
  return (n % 2) ? x * power(x, n - 1) % 1000000007
                 : power(x * x % 1000000007, n / 2);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> A;
  long long a = 0;
  long long b = 0;
  for (long long i = (long long)0; i < (long long)N; i++) {
    long long inp;
    cin >> inp;
    vector<long long> A;
    if (inp >= a) {
      b = a;
      a = inp;
    }
  }
  if (a == b) {
    for (long long i = (long long)0; i < (long long)N; i++) {
      cout << a << endl;
    }
  } else {
    for (long long i = (long long)0; i < (long long)N; i++) {
      if (A[i] == a)
        cout << b << endl;
      else
        cout << a << endl;
    }
  }
  return 0;
}
