#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n;
int a[MAXN], FMax[MAXN], SMax[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  FMax[1] = a[1];
  SMax[1] = a[1];
  for (int i = 2; i <= n; i++) {
    if (a[i] >= FMax[i - 1])
      FMax[i] = a[i], SMax[i] = FMax[i - 1];
    else if (a[i] > SMax[i - 1])
      FMax[i] = FMax[i - 1], SMax[i] = a[i];
    else
      FMax[i] = FMax[i - 1], SMax[i] = SMax[i - 1];
  }
  for (int i = 1; i <= n; i++)
    printf("%d\n", (FMax[n] == a[i]) ? SMax[n] : FMax[n]);
}
