#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> P;

int main() {
    int n;cin>>n;
    map<int,int> lr;
    vector<int> unko(n,-1);
    for(int i = 0; i < n; i++){
        int num;cin>>num;
        if(lr.count(num)==0)unko[i]=num;
        lr[num]=i;
    }
    priority_queue<P> que;
    for(int i=0;i<n;i++){
        if(unko[i]>=1){
            que.push(make_pair(unko[i],lr[unko[i]]));
        }
        while(que.top().second<i)que.pop();
        cout<<(!i)+" "<<que.top().first;
    }
    cout<<endl;
    return 0;
}