#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), copy(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> a.at(i);
    copy.at(i) = a.at(i);
  }
  sort(copy.begin(), copy.end());
  reverse(copy.begin(), copy.end());
  int p_1 = copy.at(0), p_2 = copy.at(1);
  for (i = 0; i < n; i++) {
    if (a.at(i) != p_1) {
      cout << p_2 << endl;
    } else {
      cout << p_1 << endl;
    }
  }
}
