#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int max_val = *max_element(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    if (A.at(i) == max_val) {
      vector<int> B(N);
      B = A;
      B.erase(B.begin() + i);
      max_val = *max_element(B.begin(), B.end());
    }
    cout << max_val << endl;
  }
}
