#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int ucitaj()
{
	int rez=0;
	char ch;
	while(true)
	{
		ch=getchar();
		if (ch<'0' or ch>'9') break;
		rez=rez*10+(ch-'0');
	}
	return rez;
}
int main()
{
	int n,ix,max,km,i,pom;
	ix=0;
	vector <int> A;
	n=ucitaj();
	if (n==2)
	{
		A.pb(ucitaj());
		A.pb(ucitaj());
		printf("%d ",A[1]);
		printf("%d",A[0]);
		goto kraj;
	}
	for (i=0;i<n;i++)
	{
		A.pb(ucitaj());
	}
	pavl:
	max=A[ix];
	km=ix;
	for (i=ix;i<n;i++)
	{
		if (A[i]>=max)
		{
			max=A[i];
			km=i;
		}
	}
	if (A[ix]==max and ix!=n-1)
	{
		 
		luka:
		ix++;
		if(A[ix]==max and ix!=n-1)
		{
			goto luka;
		}
		else
		{
			goto pavl;
		}
	}
	else
	{
		
		if (ix==n-1)
		{
			
			pom=A[n-1];
			A[n-1]=A[n-2];
			A[n-2]=pom;
			
		}
		else
		{
			pom=A[km];
			A[km]=A[ix];
			A[ix]=pom;
		}
	}
	
	for (i=0;i<n;i++)
		{
			printf("%d ",A[i]);
		}
	
	kraj:
		pom=0;
}