/**
 * 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),e);
        for(int i=0;i<n_;++i) dat[i+n]=v[i];
        for(int i=n-1;i>0;--i) dat[i]=min(dat[(i<<1)],dat[(i<<1)+1]);
    }

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

    T mn(int l,int r){
        l+=n;r+=n;
        T s=e;
        while(l<r){
            if(r&1){
                --r;
                s=min(s,dat[r]);
            }
            if(l&1){
                s=min(s,dat[l]);
                ++l;
            }
            l>>=1,r>>=1;
        }
        return s;
    }

    T operator[](int i){return dat[i+n];}
};

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