#include<iostream>
#include<stack>
#include<algorithm>

using namespace std;


const int maxn=1000005;


//int cmp(int x,int y)
//{
//    return x>y?1:0;
//}

int main()
{
    int n;
    while(cin>>n)
    {
        /*排序比对的低级做法
        int max=-1e9;
        int a[maxn];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]>max)
                max=a[i];
        }
        sort(a,a+n,cmp);
        stack<int> st;
        for(int i=0;i<n;i++)
        {
            st.push(a[i]);
        }*/

        int a[maxn];
        stack<int> st;
        int max=n; //因为1->n的排列

        //题意是字典序最大,部分有序:所以从max开始输出
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]==max)
            {
                cout<<max<<" ";
                max--;
            }
            else{
                st.push(a[i]);
            }
        }

        while(!st.empty())
        {
            //出栈的三步操作:判空、输出顶部、弹出
            cout<<st.top()<<" ";
            st.pop();
        }

        cout<<endl; //最后换行的处理
    }
    return 0;
}