#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; int main(){ int N, headV; while(cin >> N >> headV){ vector<int> arr; arr.push_back(headV); for(int i=0;i<N-1;i++){ int back, front; cin >> back >> front; vector<int>::iterator it = find(arr.begin(),arr.end(), front); if(it!=arr.end()){ arr.insert(it+1, back); }else{ arr.push_back(back); } } int remove; cin >> remove; arr.erase(find(arr.begin(),arr.end(), remove)); for(auto i: arr){ cout << i << " "; } cout << endl; } return 0; }