#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a.at(i);
  int max1 = max(a.at(0), a.at(1));
  int max2 = min(a.at(0), a.at(1));
  for (int i = 2; i < n; i++) {
    if (a.at(i) > max1) {
      max1 = a.at(i);
      max2 = max1;
    } else if (a.at(i) > max2)
      max2 = a.at(i);
  }
  for (int i = 0; i < (int)(n); i++) {
    if (a.at(i) == max1)
      cout << max2 << endl;
    else
      cout << max1 << endl;
  }
}
