#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
int comparetor (const void * a, const void * b)
	{
		return ( *(int*)b - *(int*)a );
	}
int main()
{
	int i,N,pom,j;
	scanf("%d",&N);
	int A[N],C[N];
	for(i=0;i<N;i++){
	scanf("%d",&A[i]);
	C[i]=A[i];
	}
	qsort(C, N, sizeof(int), comparetor);
	for(i=0;i<N;i++){
		if(A[i]!=C[i]){
			for(j=N-1;j>i;j--)
			if(A[j]==C[i]){
				pom=A[i];
				A[i]=A[j];
				A[j]=pom;
				break;		
			}
			break;
		}
	}
	for(i=0;i<N;i++)
	printf("%d ",A[i]);
	return 0;
}