#include<iostream>
#include<string>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
int maximumSwap(int num) {
    int maxi = 0;
    for (int p=1; p<=num; p*=10)
        for (int q=p; q<=num; q*=10)
            maxi = max(maxi, num + num/p%10*(q-p) + num/q%10*(p-q));
    return maxi;
}
int main(){
	int n,cifra,broj,rez,br,stepen;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>cifra;
		broj=broj*10+cifra;
	}
	rez=maximumSwap(broj);
	stringstream ss;
	ss << rez;
	string str = ss.str();
	for(int j=0;j<str.length();j++){
		printf("%c ",str[j]);
	}
	return 0;
}