#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
long long gcd(long long x, long long y) { return (y == 0) ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return x * y / gcd(x, y); }
bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  long long n, a, large = 0, large2 = 0, tmp;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (large < a) {
      large = a;
      tmp = i;
    }
    if (large >= a && large2 < a) large2 = a;
  }
  for (int i = 0; i < n; i++) {
    if (i == tmp)
      cout << large2 << endl;
    else
      cout << large << endl;
  }
  return 0;
}
