#include <iostream>
#include <forward_list>

using namespace std;

int main() {
    int n = 0;

    while(cin >> n){
        forward_list<int> slist;

        int head = 0;
        int newnum = 0;
        int oldnum = 0;
        int pos = 0;
        int de = 0;

        cin >> head;

        slist.push_front(head);

        n--;
        while(n--){
            cin >> newnum >> oldnum;
            forward_list<int>::iterator it;
            it = slist.begin();
            for(;it!=slist.end();it++){
                if(*it==oldnum)
                    slist.emplace_after(it, newnum);
            }
        }

        cin >> de;

        slist.remove(de);

        forward_list<int>::iterator it = slist.begin();
        for(;it!=slist.end();it++){
            cout << *it << ' ';
        }


    }
}