#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1.0);   const double EPS = 1E-6;   const int INF = 2 * (1e+9) + 1;   const int MAXN = 3 * 100000001;   const int MOD = (1e+9) + 7;   int n, m;   map<int, int> m1, m2;   map<int, int> u, cnt;   int main() {     cin >> n;     for (int i = 0; i < (n); ++i) {       int t1, t2;       cin >> t1 >> t2;       m1[t1] = t2;       m2[t2] = t1;       cnt[t1]++;       cnt[t2]++;     }     int cur = 0;     vector<int> ans(n);     int inx = 1;     while (inx < n) {       cur = m1[cur];       ans[inx] = cur;       u[cur] = 1;       inx += 2;       if (!cur) break;     }     cur = 0, inx = n - 2;     while (inx >= 0) {       cur = m2[cur];       if (!cur) break;       ans[inx] = cur;       u[cur] = 1;       inx -= 2;     }     if (n % 2 == 0) {       for (map<int, int>::iterator it = m1.begin(); it != m1.end(); it++) {         if (!u[it->first] && it->first) {           ans[0] = it->first;         }       }     } else {       for (map<int, int>::iterator it = m1.begin(); it != m1.end(); it++) {         if (cnt[it->first] == 1 && (!u[it->first])) {           ans[0] = it->first;           cur = ans[0], inx = 2;           while (inx < n) {             cur = m1[cur];             ans[inx] = cur;             u[cur] = 1;             inx += 2;             if (!cur) break;           }           break;         }       }     }     for (int i = 0; i < ((int)(ans).size()); ++i) {       cout << ans[i] <<    ;     }     return 0;   }   