#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
double tick() {
  static clock_t oldt, newt = clock();
  double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
  oldt = newt;
  return diff;
}
float roundoff(float val, float p) {
  return floor(val * pow(10.0, p) + 0.5) / pow(10.0, p);
}
long long int power(long long int a, long long int b, long long int mod) {
  long long int x = 1, y = a;
  while (b > 0) {
    if (b & 1) {
      x = (x * y) % mod;
    }
    y = (y * y) % mod;
    b /= 2;
  }
  return x;
}
const int INF = 0x3f3f3f3f;
const float pi = 3.14159265;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> arr;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    arr.push_back(temp);
  }
  sort(arr.rbegin(), arr.rend());
  int m = arr[0], mm = arr[1];
  for (int i = 0; i < n; i++) {
    if (arr[i] == n)
      cout << mm << '\n';
    else
      cout << m << '\n';
  }
  return 0;
}
