#include <cstring>
#include <iostream>
using namespace std;
int ne[10010];
int main() {
    int n ;
    int hn;
    cin >> n >> hn;
    int nc = n;
    memset(ne, -1, sizeof(ne));
    n--;
    while (n) {
        int a, b;
        cin >> a >> b;
        if (ne[b] != -1) {
            int sw = ne[b];
            ne[b] = a;
            ne[a] = sw;
        } else {
            ne[b] = a;
        }
        n--;
    }
    int de;
    cin >> de;
    while (hn!=-1) {
        if (hn == de) {
            hn = ne[hn];
            continue;
        };
        cout << hn << ' ';
        hn = ne[hn];
    }
}
// 64 位输出请用 printf("%lld")