#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  vector<int> vec1(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    vec[i] = x;
    vec1[i] = x;
  }
  sort(vec.begin(), vec.end());
  int First = vec[n - 1];
  int Second = vec[n - 2];
  for (int i = 1; i < n + 1; i++) {
    if (vec[i] == First) {
      cout << Second << endl;
    } else {
      cout << First << endl;
    }
  }
}
