#include <cstddef>
#include <iostream>
#include <vector>
using namespace std;
int len;//-------指向最后一位的索引
struct node{
int n;
node* next;
node(){n = 0; next = nullptr;}
node(int x){n = x; next = nullptr;}
node(int x, node* p){n = x; next = p;}
};
int main() {
int n, h;
cin >> n >> h;
vector<node> vec((int)1e3 + 10, node(0));//--------注意要提前开好大小,不能用push_back往里面加因为vector扩容(开一个更大的空间,把原数组复制过去)指针会偏移
auto change = [&](int x, int y) -> node*{//-------令x的指针指向y,并返回y的指针
for (int i = 0; i <= len; i++){
if (vec[i].n == x){
node* temp = vec[i].next;
vec[i].next = &vec[len];
return temp;
}
}
return nullptr;//--------虽然上面的return一定会有返回值但是如果这里不返回的话,编译无法通过
};
vec[0].n = h;
int a, b;
len = 0;//len is -> now
for (int i = 0; i < n - 1; i++){
cin >> a >> b;
len++;
vec[len].n = a;
vec[len].next = change(b, a);
}
node* i = &vec[0];
int x;
cin >> x;
while (i != nullptr){
if (i->n != x)//------跳过被删除的数
cout << i->n << " ";
i = i->next;
}
return 0;
}
// 64 位输出请用 printf("%lld")