#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef struct
{
	unsigned long long int b;
	int a;
	
}Br;

bool poredi(Br k, Br j)
{
	return k.a > j.a;
}

int main()
{
	vector<Br> v;
	vector<Br> k;
	unsigned long long int N;
	int w;
	Br x;
	
	cin >> N;
	for(unsigned long long int i = 0; i < N; i++)
	{
		cin >> x.a;
		x.b = i;
		v.push_back(x);
	}
	k = v;
	sort(k.begin(), k.end(), poredi);
	
	for(unsigned long long int i = 0; i < N; i++)
	{
		if(v[i].a != k[i].a)
		{
			w = v[i].a;
			v[i].a = k[i].a;
			v[k[i].b].a = w;
			goto Ispis;
		}
	}
	
	Ispis:
	cout << endl;
	for(unsigned long long int i = 0; i < N; i++)
	{
		cout << v[i].a << " ";
	}
	cout << endl;
	
	
	return 0;
}