#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  vector<int> sa(n);
  copy(a.begin(), a.end(), sa.begin());
  sort(sa.begin(), sa.end(), greater<int>());
  int m1 = sa.front(), m2 = sa.front();
  for (int i = 0; i < n; i++) {
    if (sa.at(i) == m1) {
      continue;
    }
    m2 = sa.at(i);
    break;
  }
  for (int i = 0; i < n; i++) {
    if (a.at(i) == m1) {
      cout << m2 << endl;
    } else {
      cout << m1 << endl;
    }
  }
  return 0;
}
