#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned N;
  vector<unsigned> A;
  std::vector<unsigned> vec;
  cin >> N;
  A.resize(N);
  for (unsigned i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (unsigned i = 0; i < N; ++i) {
    vector<unsigned> index = A;
    index[i] = index.back();
    index.pop_back();
    unsigned max = *max_element(index.begin(), index.end());
    cout << max << endl;
    std::vector<unsigned>(index).swap(vec);
  }
}
