#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, i, j, k, t, l;
  cin >> n;
  long long a[n + 5], b[n + 5];
  long long max = 0, max2 = 0;
  cin >> a[0];
  b[0] = a[0];
  for (i = 1; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a, a + n);
  max2 = a[0];
  max = a[0];
  for (i = 1; i < n; i++) {
    if (a[i] > max) {
      max2 = max;
      max = a[i];
    }
  }
  for (i = 0; i < n; i++) {
    if (b[i] == max)
      cout << max2 << endl;
    else
      cout << max << endl;
  }
}
