#include<iostream>
using namespace std;
int main(){
  int i,N,A,1st=0,2nd,1no=0;
  cin >> N;
  for(i=0;i<N;i++){
    cin >> A;
    if(i==0){
      1st=A;
      2nd=A;
    }
    if(A>=1st){
      2nd=1st;
      1st=A;
      1no=i;
    }
  }
  for(i=0;i<N;i++){
    if(i==1no){
      cout << 2nd << endl;
    }else{
      cout << 1st << endl;
    }
  }
}