#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  scanf("%d", &N);
  int A[N];
  int c;
  int f = 0;
  int s = 0;
  int f_index = 0;
  int s_index = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 0; i < N; i++) {
    c = A[i];
    if (c >= f) {
      s = f;
      s_index = f_index;
      f = c;
      f_index = i;
    }
    if (c >= s)
      ;
    s = c;
    s_index = i;
  }
  for (int i = 0; i < N; i++) {
    if (i != f_index) {
      printf("%d\n", f);
    } else {
      printf("%d\n", s);
    }
  }
  return 0;
}
