import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static ArrayList<Integer> lista = new ArrayList<Integer> ();
	
	public static String nadjiNajveci(int pocetak, int kraj) {
		int maks = 0;
		int index = 0;
		for (int i = pocetak; i < kraj; i++) {
			if (lista.get(i) > maks) {
				maks = lista.get(i);
				index = i;
			}
		}
		
		return maks + ";" + index;
	}
	
	public static void stampaj() {
		for (int broj : lista) {
			System.out.print(broj + " ");
		}
	}
	
	public static void main(String[] args) {
		Scanner ulaz = new Scanner(System.in);
		
		int n = ulaz.nextInt();
		
		if (n == 2) {
			int a = ulaz.nextInt(), b = ulaz.nextInt();
			System.out.println(b + " " + a);
			return;
		}
		
		for (int i = 0; i < n; i++) {
			lista.add(ulaz.nextInt());
		}
		
		for (int i = 0; i < n; i++) {
			int pocetak = lista.get(i);
			String s = nadjiNajveci(i, n);
			int max = Integer.parseInt(s.split(";")[0]);
			if (max > pocetak) {
				int maxi = Integer.parseInt(s.split(";")[1]);
				lista.set(maxi, pocetak);
				lista.set(i, max);
				break;
			}
		}
		
		stampaj();
	}
	
}