//package police;

import java.util.Arrays;
import java.util.Scanner;

public class Police {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        
        int niz[] = new int[n];
        
        int cifre[] = new int[9];
        
        for (int i = 0; i < n; i++) {
            niz[i] = in.nextInt();
            cifre[niz[i]-1] += 1;
        }
        
        int temp;
        int br = 0;
        boolean boi = true;
        
        for (int i = 8; i > 0; i--) {
            if (cifre[i]!=0) {
                if(niz[br] == i+1) {
                    br++;
                    cifre[i] --;
                    i++;
                }else{
                    boi = false;
                    if(cifre[i] == 1){
                    for (int j = br; j < n; j++) {
                            if(niz[j]==i+1){
                                temp = niz[br];
                                niz[br] = niz[j];
                                niz[j] = temp;
                            }
                    }
                    break;
                    }else{
                        cifre[i]--;
                    }
                }
                
            }
        }
        if(boi){
            temp = niz[n-2];
            niz[n-2] = niz[n-1];
            niz[n-1] = temp;
        }
        
        System.out.println(Arrays.toString(niz));
        
    }
    
}