#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e6 + 5;
int c[15], d[15], arr[N], i, j, n, l, p;

void print_arr() {
	for (int i = 0; i < n; i++) {
		cout << arr[i] << ' ';
	}
}

int rfind(int arr[],int n,int x) {
	for (int i = n - 1; i >= 0; i--) {
		if (arr[i] == x)return i;
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	for (i = 0, cin >> n; i < n; i++) {
		cin >> arr[i];
		c[arr[i]]++;
	}
	j = p = 0;
	for (i = 9; i >= 0; i--) {
		for (j; j < c[i] + p; j++) {
			if (arr[j] < i) {
				l = rfind(arr, n, i);
				swap(arr[l], arr[j]);
				print_arr();
				return 0;
			}
		}
		p += j - p;

	}
	for (i = 0; i < 10; i++) {
		if (c[i] > 1) {
			print_arr();
			return 0;
		}
	}
	swap(arr[n - 1], arr[n - 2]);
	print_arr();
	return 0;
}