#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.at(i);
    b.at(i) = a.at(i);
  }
  sort(b.begin(), b.end(), greater<int>());
  int max1 = b.at(0), max2 = b.at(0);
  for (int i = 0; i < n; i++) {
    if (max2 > b.at(i)) {
      max2 = b.at(i);
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a.at(i) == max1) {
      cout << max2 << endl;
    } else {
      cout << max1 << endl;
    }
  }
}
