#include<bits/stdc++.h>
using namespace std;
int n;
stack<int> s;
stack<int> z;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
if(s.empty()){
s.push(x);
}else{
int w=s.top();
if(x<=w){
s.push(x);
}
}
}
while(!s.empty()){
cout<<s.top()<<endl;
s.pop();
}
return 0;
}