#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	bool l = 0;
	int n, temp, maxvalue, mxva, oh = 0, d, nxtavai;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	if (n == 2) {
		temp = a[0];
		a[0] = a[1];
		a[1] = temp;
	}
	for (int i = 0; i < n; i++) {
		if (a[i] >= a[i + 1]) oh++;
		if (oh == (n - 1)) l = 1;
		if (l != 1) {
			maxvalue = *max_element(a.begin(), a.end());
			mxva = distance(a.begin(), max_element(a.begin(), a.end()));
			if (maxvalue >= a[0]) {
				temp = a[mxva];
				a[mxva] = a[0];
				a[0] = temp;
			}
			else {
				temp = a[mxva];
				a[mxva] = a[1];
				a[1] = temp;
			}
		}
		else {
			temp = a[n - 1];
			a[n - 1] = a[n - 2];
			a[n - 2] = temp;
		}
		for (int i = 0; i < n; i++)
			cout << a[i] << " ";
		return 0;
	}
}