#include <bits/stdc++.h>
using namespace std;
map<int, int> dp;
int solve(int st, map<int, int>& m) {
  if (dp.count(st) == 0) {
    return 0;
  }
  if (dp[st] != -1) return dp[st];
  dp[st] = 0;
  return dp[st] = 1 + solve(m[st], m);
}
int main() {
  int n;
  cin >> n;
  map<int, int> m;
  map<int, int> b;
  set<int> s;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    if (x) s.insert(x);
    if (y) s.insert(y);
    m[x] = y;
    b[y] = x;
    if (x) dp[x] = -1;
    if (y) dp[y] = -1;
  }
  vector<int> ans(n + 1);
  int po = 0, ini = 2;
  int num = n;
  while (ini <= n && m.count(po)) {
    ans[ini] = m[po];
    --num;
    if (s.count(ans[ini])) s.erase(ans[ini]);
    if (dp.count(ans[ini])) dp.erase(ans[ini]);
    po = m[po];
    ini += 2;
  }
  po = -1;
  for (auto it = s.begin(); it != s.end(); ++it) {
    int v = *it;
    if (dp[v] == -1) {
      solve(v, m);
    }
    if (dp[v] == num) {
      po = v;
    }
  }
  ini = 1;
  if (po != -1) {
    while (ini <= n && m.count(po)) {
      ans[ini] = po;
      ini += 2;
      po = m[po];
    }
  }
  for (int i = 1; i <= n; ++i) {
    cout << ans[i] << " ";
  }
  return 0;
}
