#include <bits/stdc++.h>
using namespace std;
set<int> ss;
set<int>::iterator it;
map<int, int> b, f;
int in[1000006], out[1000006];
int ans[1000006];
int fr[1000006];
void dfs(int val, int pos) {
  ans[pos] = val;
  if (f[val] == 0) return;
  dfs(f[val], pos + 2);
}
int main() {
  int n;
  cin >> n;
  int u, v;
  for (int i = 0; i < n; i++) {
    cin >> u >> v;
    f[u] = v;
    b[v] = u;
    if (u) in[v]++;
    if (!u) fr[v] = 1;
    ss.insert(u);
    ss.insert(v);
  }
  for (it = ss.begin(); it != ss.end(); it++) {
    if (in[*it] == 0) {
      if (fr[*it]) {
        dfs(*it, 1);
      } else {
        dfs(*it, 0);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
}
