#include <iostream>
using namespace std;

int N;

int main(){
  cin >> N;
  int a[N];
  for (int i=0;i<N;++i) cin >> A[i];
  int max = 0;
  int i_max = 0;
  int max2 = 0;
  int i_max2 = 0;
  
  for (int k=0;k<N;++k){

    if (max < A[k]) {
      max2 = max;
      max = A[k];
      i_max = k;
    }else if (A[k] > max2) {
      max2 = A[k];
      i_max2 = k;
    }
  }
  for (int j=0;j<N;++j){
    if (j == i_max) {
      cout << max2 << endl;
    } else {
      cout << max << endl;
      }
  }   
}
