#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int h = 0; h < n; h++) {
    if (h != 0) {
      a[h - 1] = ans;
    }
    ans = a[h];
    a[h] = 0;
    int ans = *max_element(a.begin(), a.end());
    cout << ans << endl;
  }
}
