#include <bits/stdc++.h>
using namespace std;
int N;
int A[200000];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  int max0 = 0, max1 = 0;
  int am0 = 0, am1 = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] >= A[am0]) {
      am1 = am0;
      am0 = i;
    } else if (A[i] >= A[am1]) {
      am1 = i;
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == am0) {
      cout << A[am1] << endl;
    } else {
      cout << A[am0] << endl;
    }
  }
  return 0;
}
