#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int ma1 = 0, ma2 = 0;
  for (int i = (0); i < (n); i++) {
    int x;
    cin >> x;
    if (a[ma1] <= x) {
      ma2 = ma1;
      ma1 = i;
    } else if (a[ma2] <= x)
      ma2 = i;
    a[i] = x;
  }
  for (int i = (0); i < (n); i++) {
    if (i == ma1)
      cout << a[ma2] << endl;
    else
      cout << a[ma1] << endl;
  }
}
