// editor3
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    int stack[100], temp[1000];
    int top = -1 , tempTop = -1;
    for(int i = 0; i< n; i++){
        scanf("%d",&stack[++top]);
    }
    while(top != -1){
        int curr = stack[top--];
        
        while(tempTop != -1 && temp[tempTop] > curr
            stack[++top] = temp[tempTop--];
        }
        temp[++tempTop] = curr;
    }
    while(tempTop != -1){
        printf("%d ", temp[tempTop--]);
    }
    return 0;
}