#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  decltype(b)::iterator re = unique(b.begin(), b.end());
  b.erase(re, b.end());
  int max1 = b[0];
  if (b.size() == 1) {
    for (int i = 0; i < n; i++) {
      cout << max1 << endl;
    }
  } else {
    int max2 = b[1];
    for (int i = 0; i < n; i++) {
      if (a[i] == max1) {
        cout << max2 << endl;
      } else {
        cout << max1 << endl;
      }
    }
  }
  return 0;
}
