#include <bits/stdc++.h>
#pragma warning(disable : 4996)
int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);
int _gcd(int a, int b);
int _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);
int s_asorts(const void* a, const void* b);
int s_asorts(const void* a, const void* b) {
  return (strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) { return (*(int*)b - *(int*)a); }
int s_asort(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int l_cins2(int n, long* a, long* b) {
  int i;
  for (int i = 0; i < n; i++) {
    scanf("%ld %ld", &*(a + i), &*(b + i));
  }
  return 0;
}
int i_cins(int n, int* a) {
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &*(a + i));
  }
  return 0;
}
int _gcd(int a, int b) {
  int r, tmp;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while (r) {
    if (!r) break;
    a = b;
    b = r;
    r = a % b;
  }
  return (b);
}
long _max(long a, long b) { return a > b ? a : b; }
long _min(long a, long b) { return a < b ? a : b; }
int _swp(int* a, int* b) {
  int tmp;
  tmp = *b;
  *b = *a;
  *a = tmp;
  return 0;
}
int _cknum(char* a, int n) {
  int i;
  char t = '0';
  for (i = 0; i < n; i++) {
    if (a[i] < '0' || a[i] > '9') return 1;
  }
  return 0;
}
int _atoi(char* s, int len) {
  char tmp[20];
  memcpy(tmp, s, len);
  tmp[len] = 0x00;
  return (atoi(tmp));
}
static int a[200001], x[200001];
int main(void) {
  int n;
  int i, n1, n2;
  scanf("%d", &n);
  i_cins(n, a);
  memcpy(x, a, sizeof(int) * 200000);
  qsort(x, n, sizeof(int), s_dsort);
  n1 = x[0];
  n2 = x[0];
  for (i = 1; i < n; i++) {
    if (n1 == x[i]) continue;
    n2 = x[i];
    break;
  }
  for (i = 0; i < n; i++) {
    if (a[i] != n1)
      printf("%d\n", n1);
    else
      printf("%d\n", n2);
  }
  return 0;
}
