#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  int i;
  priority_que<int> b;
  for(i=0;i<n;i++){
    cin >> a[i];
    b.push(a[i]);
  }
  
  for(i=0;i<n;i++){
    if(b.top() == a[i]){
      int tmp = b.top();
      b.pop();
      cout << b.top();
      b.push(tmp);
    }else
      cout << b.top();
  }
}
        
  
  
  
}