#include <iostream>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
	long niz[10000];	
	long max[10000];
	long polozaj[10000];
	int n,k,i,j,t,d;
	d = 0;
	
cin>>n;
for (i=1;i<=n;i++)
cin>>niz[i];
for (i=n;i>=1;i--){
if (max[i]<niz[i])
max[i]=niz[i];
else max[i]=max[i+1];
if (max[i]==niz[i])
polozaj[i]=polozaj[i+1];
else polozaj[i]=i;
}
for (i=1;i=n;i++)
if (max[i]>niz[i]){
	d=niz[i];
	niz[i]=max[i];
	niz[polozaj[i]]=d;
}
for (i=1;i<=n;i++)
cout<<niz[i];
}