#include<stdio.h>
int main(void)
{
	long long int n,a[200010],m=0,ms=0,count=0;
	scanf("%lld", &n);
	for ( int i = 0; i < n; i++)
	{
		scanf("%d",&a[i]);
	}
	for ( int i = 0; i < n; i++)
	{
		if(i==0)m = a[i];
		if (m < a[i + 1])
		{
			m = a[i + 1];
		}
	}
	for ( int i = 0; i < n; i++)
	{
		if (ms <= a[i + 1] && !a[i + 1] == m)ms = a[i + 1];

	}
	for ( int i = 0; i < n; i++)
	{
		if (m == a[i])count++;
		if (count == 2)
		{
			ms = m;
		}
	
	for ( int i = 0; i < n; i++)
	{
		if (ms == m)printf("%d", ms);
		if (ms < m && a[i] == m)printf("%d", ms);
		if (!a[i] == m && ms < m) printf("%d", m);

	}
	return 0;
}




