#include <bits/stdc++.h>
const long long mod = 1000000007;
int main() {
  int N;
  scanf("%d", &N);
  int *A = new int[N];
  int max = 0;
  int second = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    if (A[i] >= A[max]) {
      second = max;
      max = i;
    } else if (A[i] > A[second]) {
      second = i;
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == max) {
      printf("%d\n", A[second]);
    } else {
      printf("%d\n", A[max]);
    }
  }
  return 0;
}
