#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, A[200000], parson, i, j, range, maxval, next_max;
  scanf("%lld", &N);
  for (i = 0; i < N; i++) {
    scanf("%lld\n", &A[i]);
  }
  maxval = A[0];
  for (i = 0; i < N; i++) {
    if (maxval < A[i]) {
      maxval = A[i];
    }
  }
  next_max = A[0];
  for (i = 0; i < N; i++) {
    if (next_max < A[i] && A[i] != maxval) {
      next_max = A[i];
    }
  }
  for (i = 0; i < N; i++) {
    if (A[i] != maxval) {
      printf("%lld\n", maxval);
    } else {
      printf("%lld\n", next_max);
    }
  }
  return 0;
}
