#include <bits/stdc++.h>
int sum;
using namespace std;
int bigG, suneo;
int ans;
int main() {
  int a[200000], n;
  cin >> n;
  for (int i = (int)(0); i < (int)(n); i++) {
    cin >> a[i];
  }
  for (int i = (int)(0); i < (int)(n); i++) {
    if (a[i] < a[i + 1]) {
      suneo = bigG;
      bigG = a[i + 1];
    }
    if (i == 0) {
      suneo = a[i];
    }
  }
  for (int i = (int)(0); i < (int)(n); i++) {
    if (bigG == a[i]) {
      cout << suneo << endl;
    } else {
      cout << bigG << endl;
    }
  }
  return 0;
}
