#include <bits/stdc++.h>
using namespace std;
int n;
int x, y;
int p[1000003];
int r[1000003];
map<int, int> a;
int ans[200003];
int s;
int parent(int x) {
  if (p[x] < 0) return x;
  return p[x] = parent(p[x]);
}
void join(int x, int y) { p[y] = parent(x); }
int main() {
  fill_n(p, 1000003, -1);
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &x, &y);
    if (y) join(x, y);
    a.insert(pair<int, int>(x, y));
  }
  int i = 2;
  int j = 0;
  while (a[j] != 0) {
    ans[i] = a[j];
    j = a[j];
    i += 2;
  }
  i = 1;
  j = 0;
  while (p[j] < 0 || parent(j) == 0) j++;
  j = parent(j);
  ans[i] = j;
  i += 2;
  while (a[j] != 0) {
    ans[i] = a[j];
    j = a[j];
    i += 2;
  }
  for (i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
