/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=int_fast64_t;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
template<class T> struct SegMIN{
    int n;
    T e;
    vector<T> dat;

    SegMIN(vector<T> v,T e_){
        int n_=v.size();
        n=1;e=e_;
        while(n<n_) n<<=1;
        dat.resize((n<<1)-1,e);
        fr(i,n_) dat[i+n-1]=v[i];
        for(int i=n_+n-1;i<(n<<1)-1;++i) dat[i]=e;
        ifr(i,n-1) dat[i]=min(dat[(i<<1)+1],dat[(i<<1)+2]);
    }

    void ud(int k,T c){
        k+=n-1;
        dat[k]=c;
        while(k>0){
            k=(k-1)>>1;
            dat[k]=min(dat[(k<<1)+1],dat[(k<<1)+2]);
        }
    }

    T mn(int be,int en,int k,int l,int r){
        if(r<=be||en<=l) return e;
        if(be<=l&&r<=en) return dat[k];
        return min(mn(be,en,(k<<1)+1,l,(l+r)>>1),mn(be,en,(k<<1)+2,(l+r)>>1,r));
    }

    T mn(int be,int en){
        return mn(be,en,0,0,n);
    }

    T getv(int k){
        return dat[k+n-1];
    }
};

class EYoungMaids {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n;
        in>>n;
        vector<int> O(n/2),E(n/2),f(n+1);
        fr(i,n/2) in>>O[i]>>E[i],f[O[i]]=f[E[i]]=i;
        SegMIN<int> o(O,INT_MAX),e(E,INT_MAX);
        using P=tuple<int,int,int,int,bool>;
        priority_queue<P,vector<P>,greater<P>> pq;
        int a=o.mn(0,n/2),b=e.mn(f[a],n/2);
        pq.emplace(a,b,0,n/2,false);
        bool g;
        int s,t,l,r;
        vector<int> ans;
        while(!pq.empty()){
            tie(a,b,s,t,g)=pq.top();pq.pop();
            ans.emplace_back(a);ans.emplace_back(b);
            l=f[a],r=f[b];
            if(g){
                if(s!=l){
                    a=e.mn(s,l);
                    if(a>n) return;
                    pq.emplace(a,o.mn(f[a]+1,l+1),s,l,true);
                }
                if(l+1!=r){
                    a=o.mn(l+1,r);
                    if(a>n) return;
                    pq.emplace(a,e.mn(f[a],r),l+1,r,false);
                }
                if(r!=t){
                    a=e.mn(r,t);
                    if(a>n) return;
                    pq.emplace(a,o.mn(f[a]+1,t+1),r,t,true);
                }
            }
            else{
                if(s!=l){
                    a=o.mn(s,l);
                    if(a>n) return;
                    pq.emplace(a,e.mn(f[a],l),s,l,false);
                }
                if(l!=r){
                    a=e.mn(l,r);
                    if(a>n) return;
                    pq.emplace(a,o.mn(f[a]+1,r+1),l,r,true);
                }
                if(r+1!=t){
                    a=o.mn(r+1,t);
                    if(a>n) return;
                    pq.emplace(a,e.mn(f[a],t),r+1,t,false);
                }
            }
        }
        for(auto i:ans) out<<i<<" ";
        out<<endl;
    }
};

int main() {
    EYoungMaids solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 7796