#include <bits/stdc++.h>
using namespace std;
const long long INFL = 1LL << 60;
const int INF = 1 << 30;
const long long MOD = 1e9 + 7;
vector<long long> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<long long> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long pow_long(long long x, long long k) {
  long long res = 1;
  while (k > 0) {
    if (k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
long long pow_mod(long long x, long long k) {
  x %= MOD;
  x += MOD;
  x %= MOD;
  long long res = 1;
  while (k > 0) {
    if (k % 2) {
      res *= x;
      res %= MOD;
    }
    x *= x;
    x %= MOD;
    k /= 2;
  }
  return res;
}
long long inverse(long long x) { return pow_mod(x, MOD - 2); };
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; };
int main(void) {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) cin >> A[i];
  vector<long long> B = A;
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  long long a = B[0];
  long long b = B[1];
  if (a == b) {
    for (long long i = 0; i < N; i++) cout << a << endl;
    return 0;
  }
  for (long long i = 0; i < N; i++) {
    if (A[i] == a)
      cout << b << endl;
    else
      cout << a << endl;
    return 0;
  }
}
