#include<cstdio>
int main(){
  cin >> n;
  int a[200000];
  int max_first = 0;
  int max_second = 0;
  int tmp = 0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(max_first < a[i])
    	max_first = a[i];
    else if(max_first != a[i] && max_second < a[i])
      max_second = a[i];
  }
  
  for(int i=0; i<n; i++){
    if(i == tmp){
      cout << max_second;
    }
    else{
      cout << max_first;
    }
  }
  
 return 0;
}
