#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  int leftMax[N];
  int rightMax[N];
  leftMax[0] = 0;
  rightMax[N - 1] = 0;
  for (int i = 1; i < N; i++) leftMax[i] = max(leftMax[i - 1], A[i - 1]);
  for (int i = N - 2; i >= 0; i--) rightMax[i] = max(rightMax[i], A[i + 1]);
  for (int i = 0; i < N; i++) {
    cout << max(rightMax[i], leftMax[i]) << endl;
  }
}
