#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int inf = 0x3f3f3f3f;
int n, a[maxn], b[maxn], c[maxn];
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
  }
  b[n] = a[n];
  for (int i = n - 1; i >= 1; i--) {
    b[i] = max(b[i + 1], a[i]);
  }
  c[1] = a[1];
  for (int i = 2; i <= n; i++) {
    c[i] = max(c[i - 1], a[i]);
  }
  c[0] = 0;
  b[n + 1] = 0;
  for (int i = 1; i <= n; i++) {
    cout << max(b[i + 1], c[i - 1]) << endl;
  }
}
