#include <bits/stdc++.h>
int sum;
using namespace std;
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++) {
    int tmp = a[i];
    a[i] = 0;
    for (int i = (int)(0); i < (int)(n); i++) {
      if (a[i] < a[i + 1]) {
        ans = a[i + 1];
      }
    }
    cout << ans << endl;
    a[i] = tmp;
  }
  return 0;
}
