#include <bits/stdc++.h>
using namespace std;
int B[2000000], A[2000000];
int main() {
  ios_base::sync_with_stdio(0);
  set<int> S;
  int F, Sc, n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> A[i] >> b;
    S.insert(b);
    B[A[i]] = b;
    if (A[i] == 0) Sc = b;
  }
  for (int i = 0; i < n; i++) {
    if (S.find(A[i]) == S.end()) {
      F = A[i];
      break;
    }
  }
  int St[2000000], cnt = 2, rec = 0;
  St[0] = F;
  St[1] = Sc;
  cout << F << " " << Sc << " ";
  while (B[St[rec]] != 0) {
    cout << B[St[rec]] << " ";
    St[cnt++] = B[St[rec]];
    rec++;
  }
}
