#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n, t, j=0, c, max;
	cin >> n;
	vector <int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++)
	{
		c = i;
		max = a[i];
		for(j = n-i-1; j >= i; j--)
			if (a[j+i] > max)
			{
				max = a[j+i];
				c = i + j;
			}
		if (c != i)
		{
			a[c] = a[i];
			a[i] = max;
			break;
		}
		if (i == n - 2)
		{
			t = a[n - 2];
			a[n - 2] = a[n - 1];
			a[n - 1] = t;
		}
	}
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
}