#include <iostream>
#include <limits>

using namespace std;

typedef numeric_limits<streamsize> ignore_t;

void zamena(int &a, int &b) 
{
	int temp = a;
	a = b;
	b = temp;
}

int main() 
{
	int N{};
	
	scanf("%d\n", &N);

	int* A = new int[N];

	for (int i{}; i < N; ++i)
		cin >> A[i];
	cin.ignore(ignore_t::max(), '\n');

	if (N > 2) 
	{
		for (int i{}; i < N; ++i) 
		{
			int max{i};
			for (int j{ i + 1 }; j < N; ++j) 
				if (A[j] > A[max]) 
					max = j;

			if (A[max] > A[i]) 
			{
				zamena(A[i], A[max]);
				break;
			}
		}
	}
	else 
	{
		zamena(A[0], A[1]);
	}

	for (int i{}; i < N; ++i)
		cout << A[i] << ' ';

	cin.clear();
	cin.ignore(ignore_t::max(), '\n');
	cin.get();

	return 0;
}