#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(1000005, -1), ct(1000005, 0);
  int j, k;
  for (int i = 0; i < n; ++i) {
    cin >> j >> k;
    if (k == 0) k = -1;
    a[j] = k;
    ++ct[j];
    if (k != -1) --ct[k];
  }
  vector<int> ans(n + 2);
  k = a[0];
  j = 1;
  while (k != -1) {
    ans[j] = k;
    j += 2;
    k = a[k];
  }
  int i;
  for (i = 1; i <= 1e6; ++i)
    if (ct[i] == 1) break;
  k = i;
  j = 0;
  while (k != -1) {
    ans[j] = k;
    j += 2;
    k = a[k];
  }
  for (i = 0; i < n; ++i) cout << ans[i] << " ";
  cout << endl;
}
