#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[i];
  }
  vector<int> B(N);
  int m = A[0];
  for (int i = 0; i < N; ++i) {
    m = max(m, A[i]);
  }
  for (int i = 0; i < N; ++i) {
    if (m > A[i]) {
      B[i] = m;
    } else {
      B[i] = A[0];
      for (int j = 0; j < i; ++j) {
        B[i] = max(B[i], A[j]);
      }
      for (int j = i + 1; j < N; ++j) {
        B[i] = max(B[i], A[j]);
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    cout << B[i] << endl;
  }
  return 0;
}
