#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int maxi = 0, second = 0;
  vector<int> b = a;
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  maxi = a.at(0), second = a.at(1);
  for (int x : b) {
    if (x == maxi)
      cout << second << endl;
    else
      cout << maxi << endl;
  }
  return 0;
}
