#include <iostream>
#include <unordered_map>
using namespace std;

struct node
{
    int val;
    node* next;
    node(int x) : val(x), next(nullptr) {}
    node(int x, node* next) : val(x), next(next) {}
};

int main() {
    int n;
    cin >> n;
    int h;
    cin >> h;
    node* head = new node(h);
    unordered_map<int, node*> nodelist;
    nodelist[h] = head;
    while(n-1){
        int front, back;
        cin >> back >> front;
        node* p = new node(back);
        nodelist[back] = p;
        if(nodelist[front]->next == nullptr){
            nodelist[front]->next = p;
        }else{
            p->next = nodelist[front]->next;
            nodelist[front]->next = p;
        }
        n--;
    }
    int k;
    cin >> k;
    node* q = head;
    while(q!=nullptr){
        if(q->val == k){
            q = q->next;
            continue;
        }
        cout << q->val << ' ';
        q = q->next;
    }

    return 0;
}
// 64 位输出请用 printf("%lld")