#include <cstdio>
#include <algorithm>
#include <list>
using namespace std;
int n, t;
list<int> BST;
list<int>::iterator p;

int main()
{
    freopen(".20.in","r",stdin);
    freopen(".20.out","w",stdout);
    scanf("%d%d", &n, &t);

    BST.push_front(t);
    p = BST.begin();
    for(int i = 1 ; i < n ; i++ )
    {
        scanf("%d", &t);
        if( t < *p ) BST.insert(p, t), p--;
        else p++, BST.insert(p, t), p--;
    }
    for( p = BST.begin() ; p != BST.end() ; p++ )
        printf("%d ", *p);
}
