#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> a;
  vector<int> aSorted;
  cin >> n;
  a.resize(n);
  aSorted.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    aSorted[i] = a[i];
  }
  sort(aSorted.begin(), aSorted.end(), greater<int>());
  int maxA = aSorted[0];
  int subMaxA = aSorted[1];
  for (int i = 0; i < n; ++i) {
    cout << (a[i] == maxA ? subMaxA : maxA) << endl;
  }
}
