#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
const int MAXA = 1000010;
int nex[MAXN];
int rb[MAXA], ra[MAXA];
int a[MAXN], b[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int st = -1, stid = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    ra[a[i]] = i;
    rb[b[i]] = i;
    if (a[i] == 0) st = i;
  }
  for (int i = 1; i <= n; i++)
    if (rb[a[i]] == 0) stid = a[i];
  while (st != 0) {
    cout << stid << " ";
    int nid = b[st];
    st = ra[stid];
    stid = nid;
  }
  cout << endl;
}
