#include <iostream>
using namespace std;

int main() {
	int n;

	cin >> n;
	int array[1000000];
	int max=0;
	int position;
	for (int i = 0; i < n; i++) {
		cin >> array[i];
		if (max < array[i])max = array[i];
		
	}
	if (n == 2) {
		int hold;
		hold = array[0];
		array[0] = array[1];
		array[1] = hold;
		cout << array[0] << " " << array[1] <<endl;
	}
	else {
		for (int i = 0; i < n; i++) {
			int hold;
			if (array[i] >= max) {
				max = 0;
				for (int j = i+1; j < n; j++)
				{
					if (max <= array[j]) {
						max = array[j];
						position = j;
					}
				}
			}
			else {
				hold = array[i];
				array[i] = array[position];
				array[position] = hold;
				break;
			}
		}
		for (int i = 0; i < n; i++)cout << array[i] << " ";
	}
	
}