#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  int i;
  int b[n];
  for(i=0;i<n;i++){
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b,b+n,greater<>());
  for(i=0;i<n;i++){
    if(b[0] == a[i]) cout << b[1];
    else cout << b[0];
  }
}