#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const int N = 2e5+5;
int main(){
int n;
cin >> n;
vector<int> a(n);
set<int> cur;
int w;
vector<pair<int,int>> st;
for(int i =1;i<=n;i++){
cin >> a[i];
if(!cur.count(a[i])){
cur.insert(a[i]);
st.pb({a[i],i});
}
else{
while(st.back().fi != a[i]){
cur.erase(st.back().fi);
st.pop_back();
}
}
}
st.pb({-1,n+1});
for(int i=0;i<st.size()-1;i++){
for(int j=st[i].se;j<st[i+1].se;j++){
cout << st[i].fi << ' ';
}
}
return 0;
}