#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
int nxt[1001000];
int pre[1001000];
vector<int> odd;
vector<int> even;
set<int> shu;
int n;
int main() {
  int n;
  memset(nxt, -1, sizeof(nxt));
  memset(pre, -1, sizeof(pre));
  cin >> n;
  odd.clear();
  even.clear();
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    nxt[a] = b;
    pre[b] = a;
    if (a != 0) shu.insert(a);
    if (b != 0) shu.insert(b);
  }
  int t = nxt[0];
  while (t > 0) {
    even.push_back(t);
    t = nxt[t];
  }
  if (n % 2 == 0) {
    t = pre[0];
    while (t > 0) {
      odd.push_back(t);
      t = pre[t];
    }
  } else {
    for (set<int>::iterator ite = shu.begin(); ite != shu.end(); ite++)
      if (nxt[*ite] < 0) {
        t = *ite;
      }
    while (t > 0) {
      odd.push_back(t);
      t = pre[t];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i != 1) putchar(' ');
    if (i % 2 == 0) {
      printf("%d", even[i / 2 - 1]);
    } else {
      printf("%d", odd[odd.size() - i / 2 - 1]);
    }
  }
  printf("\n");
  return 0;
}
