#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> a.at(i);
  }
  int maxi = *max_element((a).begin(), (a).end());
  for (long long i = 0; i < (long long)(n); i++) {
    if (a.at(i) != maxi)
      cout << maxi << endl;
    else {
      a.at(i) = 0;
      cout << *max_element((a).begin(), (a).end()) << endl;
      a.at(i) = maxi;
    }
  }
}
