#include <iostream>
using namespace std;
struct ListNode {
    int val;
    struct ListNode* next;
    ListNode(int x) : val(x), next(nullptr) {}
};
int main() {
    int n, h, a, b;

    cin >> n;
    auto* head = new ListNode(0), *ph = new ListNode(0);
    cin >> h;
    head->val = h;
    head->next = nullptr;
    n--;
    while (n--) {
        cin >> a >> b;
        for (auto ph = head; ph != nullptr; ph = ph->next) {
            if (b == ph->val) {
                auto* nd = new ListNode(a);
                nd->next = ph->next;
                ph->next = nd;
            }
        }
    }
    int del;
    cin >> del;
    for (auto cur = head; cur != nullptr; cur = cur->next) {
        if (cur->val != del)cout << cur->val << ' ';
    }
}
// 64 位输出请用 printf("%lld")