#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  map<int, int> m, m_reverse;
  while (cin >> n) {
    m.clear();
    m_reverse.clear();
    int front, back;
    for (int i = 1; i <= n; i++) {
      cin >> front >> back;
      if (back == 0) back = -1;
      m[front] = back;
      m_reverse[back] = front;
    }
    front = 0;
    queue<int> q;
    stack<int> s;
    while (!q.empty()) q.pop();
    while (!s.empty()) s.pop();
    while (m[front] != 0 && m[front] != -1) {
      q.push(m[front]);
      m_reverse.erase(m[front]);
      m.erase(front);
      front = q.back();
    }
    if (m[q.back()] == -1) {
      m_reverse.erase(-1);
      m.erase(q.back());
      queue<int> q1;
      stack<int> s1;
      while (!q1.empty()) q1.pop();
      while (!s1.empty()) s1.pop();
      int temp = m.begin()->first;
      int temp_temp = temp;
      q1.push(temp);
      while (m[temp]) {
        q1.push(m[temp]);
        temp = m[temp];
      }
      temp = temp_temp;
      while (m_reverse[temp]) {
        s1.push(m_reverse[temp]);
        temp = m_reverse[temp];
      }
      if (s1.size()) {
        cout << s1.top();
        s1.pop();
      } else {
        cout << q1.front();
        q1.pop();
      }
      while (!q1.empty()) {
        cout << ' ' << q.front();
        q.pop();
        if (s1.empty()) {
          cout << ' ' << q1.front();
          q1.pop();
        } else {
          cout << ' ' << s1.top();
          s1.pop();
        }
      }
      cout << endl;
    } else {
      back = -1;
      while (m_reverse[back]) {
        s.push(m_reverse[back]);
        back = m_reverse[back];
      }
      cout << s.top();
      s.pop();
      while (!s.empty()) {
        cout << ' ' << q.front() << ' ' << s.top();
        s.pop();
        q.pop();
      }
      cout << ' ' << q.front() << endl;
      q.pop();
    }
  }
}
