Problem: During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.

Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of the student that stands in line directly in front of him, and the student that stands in line directly behind him. If no one stands before or after a student (that is, he is the first one or the last one), then he writes down number 0 instead (in Berland State University student IDs are numerated from 1).

After that, all the students went about their business. When they returned, they found out that restoring the queue is not such an easy task.

Help the students to restore the state of the queue by the numbers of the student ID's of their neighbors in the queue.

Input

The first line contains integer n (2 ≤ n ≤ 2·105) — the number of students in the queue. 

Then n lines follow, i-th line contains the pair of integers ai, bi (0 ≤ ai, bi ≤ 106), where ai is the ID number of a person in front of a student and bi is the ID number of a person behind a student. The lines are given in the arbitrary order. Value 0 is given instead of a neighbor's ID number if the neighbor doesn't exist.

The ID numbers of all students are distinct. It is guaranteed that the records correspond too the queue where all the students stand in some order.

Output

Print a sequence of n integers x1, x2, ..., xn — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one.

Examples

Input

4
92 31
0 7
31 0
7 141


Output

92 7 31 141 

Note

The picture illustrates the queue for the first sample.

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
double exact(long long int a, long long int b) { return (double)a / b; }
long long int gcd(long long int a, long long int b) {
  if (a == 0 || b == 0) {
    return (a + b);
  }
  return gcd(b, a % b);
}
long long int fastExpo(long long int a, long long int n, long long int mod) {
  long long int result = 1;
  while (n > 0) {
    if (n & 1) result = (result * a) % mod;
    a = (a * a) % mod;
    n >>= 1;
  }
  return result;
}
long long int modInverse(long long int n, long long int mod) {
  return fastExpo(n, mod - 2, mod);
}
vector<long long int> factorial(long long int n) {
  std::vector<long long int> fac(n + 2, 0);
  fac[0] = 1;
  for (long long int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % 1000000007;
  return fac;
}
long long int __nCr(long long int n, long long int r,
                    vector<long long int>& Fact, long long int mod) {
  long long int ans = (((Fact[n] * modInverse(Fact[r], mod)) % mod) *
                       modInverse(Fact[n - r], mod)) %
                      mod;
  return ans;
}
vector<long long int> sieve(long long int n) {
  vector<long long int> v(n + 2, 0);
  vector<long long int> primes;
  n++;
  v[0] = 1;
  for (long long int i = 2; i < n; i++) {
    if (!v[i]) {
      primes.push_back(i);
      for (long long int j = 2 * i; j < n; j += i) v[j]++;
    }
  }
  return primes;
}
long long int search(vector<pair<long long int, long long int>>& v,
                     long long int x, long long int l, long long int r) {
  while (l <= r) {
    long long int mid = (l + r) / 2;
    if (v[mid].first == x) {
      return v[mid].second;
    } else if (v[mid].first > x) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return -1;
}
bool search_array(vector<long long int>& arr, long long int val,
                  long long int i, long long int j) {
  while (i <= j) {
    long long int mid = (i + j) / 2;
    if (arr[mid] == val) {
      return true;
    } else if (arr[mid] > val) {
      j = mid - 1;
    } else {
      i = mid + 1;
    }
  }
  return false;
}
void solve(long long int T) {
  long long int n;
  cin >> n;
  vector<long long int> arr, brr;
  map<long long int, long long int> m;
  vector<pair<long long int, long long int>> v, temp;
  for (long long int i = 0; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    v.push_back({x, y});
    temp.push_back({y, x});
    arr.push_back(x);
    brr.push_back(y);
    m[x]++;
    m[y]++;
  }
  sort(arr.begin(), arr.end());
  long long int first, last;
  for (auto each : m) {
    if (m[each.first] == 1) {
      bool flag = search_array(arr, each.first, 0, n - 1);
      if (flag) {
        first = each.first;
        break;
      }
    }
  }
  sort(v.begin(), v.end());
  long long int second = search(v, 0, 0, n - 1);
  vector<long long int> v1, v2;
  v1.push_back(first);
  long long int b = search(v, first, 0, n - 1);
  if (b != 0) v1.push_back(b);
  bool flag = true;
  while (flag && b != 0) {
    long long int a = search(v, b, 0, n - 1);
    if (a == -1 || a == 0) {
      flag = false;
      break;
    }
    v1.push_back(a);
    b = a;
  }
  sort(temp.begin(), temp.end());
  v2.push_back(second);
  long long int b1 = second;
  bool flag1 = true;
  while (flag1) {
    long long int a = search(v, b1, 0, n - 1);
    if (a == -1 || a == 0) {
      flag1 = false;
      break;
    }
    v2.push_back(a);
    b1 = a;
  }
  long long int i = 0, j = 0;
  vector<long long int> ans;
  while (i < v1.size() && j < v2.size()) {
    ans.push_back(v1[i]);
    ans.push_back(v2[j]);
    i++;
    j++;
  }
  while (i < v1.size()) {
    ans.push_back(v1[i]);
    i++;
  }
  while (j < v2.size()) {
    ans.push_back(v2[j]);
    j++;
  }
  for (long long int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T = 1;
  for (long long int t = 1; t <= T; t++) {
    solve(t);
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}