#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, t;
  deque<long long> l;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> t;
    l.push_back(t);
  }
  long long s = 0;
  long long k = *max_element(l.begin(), l.end());
  for (long long i = 0; i < n; i++) {
    if (l[i] != k) {
      cout << k << endl;
    } else if (l[i] == k) {
      l.erase(l.begin() + i);
      cout << *max_element(l.begin(), l.end()) << endl;
    }
  }
}
