#include <bits/stdc++.h>
using namespace std;

int main()
{
	long long n, indmx;
	int mx;
	bool flag = true;
	scanf("%lld", &n);
	int x[n];
	
	for(long long i = 0; i < n; i++)
	{
		scanf("%d", &x[i]);
		if(i == 1) mx = x[i], indmx = i;
		if(mx <= x[i]) mx = x[i], indmx = i;
	}
	
	if(n == 2) swap(x[0], x[1]);
	for(long long i = 0; i < n; i++)
	{
		if(mx > x[i] && indmx > i && flag) swap(x[i], x[indmx]), flag = false;
		printf("%d ", x[i]);
	}
}