#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
template <typename T>
T digit(T num) {
  T sum = 0;
  while (num) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  T g = gcd(a, b);
  return a / g * b;
}
template <typename T>
T power(T a, T b) {
  T tmp = 1;
  for (long long i = 0; i < b; ++i) {
    tmp *= a;
  }
  return tmp;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (long long i = 0; i < n; ++i) cin >> a[i];
  pair<int, int> two = make_pair(0, 0);
  auto me = max_element((a).begin(), (a).end()) - a.begin();
  for (long long i = 0; i < n; ++i) {
    if (i == me) continue;
    if (two.first < a[i]) {
      two.first = a[i];
      two.second = i;
    }
  }
  for (long long i = 0; i < n; ++i) {
    if (i == me)
      cout << two.first << endl;
    else
      cout << *max_element((a).begin(), (a).end()) << endl;
  }
  return 0;
}
