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

#define NICE 69

int main(){
	int N; cin >> N;
    	map<int, int, greater<int>> m1;
	vector<int> v1;
	vector<int> v2;
	for(int i = 0; i < N; i++){
        	int a; cin >> a;
        	m1[a] = i;
		v1.push_back(a);
		v2.push_back(a);	
	}
	sort(v2.begin(), v2.end(), greater<int>());
	if(v1 == v2 && v1.size() > 1){
		int t = v1[v1.size() - 1];
		v1[v1.size() - 1] = v1[v1.size() - 2];
	       	v1[v1.size() - 2] = t;	
		goto end;
	}
	for(int i = 0; i < N; i++){
		if(v1[i] != v2[i]){
			int p = m1[v2[i]];
			int t = v1[p];
			v1[p] = v1[i];
			v1[i] = t;
			break;
		}
	}
end:
	for(auto x : v1){
		cout << x << " ";	
	}
	cout << "\n";
	return 0;
}