#include <bits/stdc++.h>
using namespace std;
void swap(int a[], int i, int j) {
  char temp;
  temp = a[i];
  a[i] = a[j];
  a[j] = temp;
}
void pushdown(int a[], int f, int l) {
  int p = f;
  int c = 2 * p;
  while (c <= l) {
    if (c < l && a[c - 1] > a[c]) c++;
    if (a[c - 1] > a[p - 1]) break;
    swap(a, c - 1, p - 1);
    p = c;
    c = 2 * p;
  }
}
void heap_sort(int a[], int n) {
  int i;
  for (i = n / 2; i > 0; i--) pushdown(a, i, n);
  for (i = n; i > 1; i--) {
    swap(a, 0, i - 1);
    pushdown(a, 1, i - 1);
  }
}
int main() {
  int N, i, j;
  cin >> N;
  int A[N], B[N];
  for (i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i];
  }
  heap_sort(B, N);
  for (i = 0; i < N; i++) {
    if (A[i] == B[0])
      cout << B[1] << endl;
    else
      cout << B[0] << endl;
  }
  return 0;
}
