#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, cm = 0, cm2 = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    cm = max(a[i], cm);
    if (cm2 < cm) cm2 = max(a[i], cm2);
  }
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] == cm) cout << cm2 << endl;
    cout << cm << endl;
  }
}
