#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long fceil(long long a, long long b) {
  return (a % b == 0 ? a / b : a / b + 1);
}
int main() {
  int n, a[200007] = {}, mx1 = 0, mx2 = 0, ctr1 = 0, ctr2 = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (a[i] >= mx1) {
      mx2 = mx1;
      mx1 = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != mx1)
      cout << mx1 << endl;
    else
      cout << mx2 << endl;
  }
  return 0;
}
