#include <bits/stdc++.h>
using namespace std;
int n, A[200005], la[200005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  la[n] = A[n];
  for (int i = n - 1; i >= 1; i--) la[i] = max(la[i - 1], A[i]);
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    printf("%d\n", max(la[i + 1], mx));
    mx = max(mx, A[i]);
  }
  return 0;
}
