#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int N, A[maxn], mx1, mx2;
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  for (int i = 0; i < N; i++) {
    if (A[i] > mx1)
      mx2 = mx1, mx1 = A[i];
    else if (A[i] > mx2)
      mx2 = A[i];
  }
  for (int i = 0; i < N; i++)
    if (A[i] == mx1)
      printf("%d\n", mx2);
    else
      printf("%d\n", mx1);
}
