#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<stdio.h>
#include<stdlib.h>
int main()
{
	int *a, n = 1, zamena = 0, tek=0;
	int maxind = 0;
	scanf("%d", &n);
	a = (int*)calloc(n, sizeof(int));
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	int i = 0;
	for (; i < n-1; i++)
	{
		int maxind = i;
		for (int j = i+1; j < n; j++)
		{
			if (a[j]>a[maxind])
			{
				maxind = j;
				zamena = 1;
			}
		}
		if (zamena == 1)
		{
			int pom = a[i];
			a[i] = a[maxind];
			a[maxind] = pom;
			break;
		}
	}

	if(!zamena)
	{
		int pom = a[n - 1];
		a[n - 1] = a[n - 2];
		a[n - 2] = pom;
	}

	printf("\n");
	for (int i = 0; i < n; i++)
		printf("%d ", a[i]);
	printf("\n");

	return 0;
}