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;
template <class T>
inline T BIGMOD(T n, T m, T mod) {
  long long int ans = 1;
  long long int k = n;
  while (m) {
    if (m & 1) {
      ans *= k;
      if (ans > mod) ans %= mod;
    }
    k *= k;
    if (k > mod) k %= mod;
    m >>= 1;
  }
  return ans;
}
template <class T>
string toString(T n) {
  ostringstream ost;
  ost << n;
  ost.flush();
  return ost.str();
}
template <class T>
string toBinary(T n) {
  string ret = "";
  while (n) {
    if (n % 2 == 1)
      ret += '1';
    else
      ret += '0';
    n >>= 1;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
void combination(int n, vector<vector<int> > &ret) {
  ret.resize(n + 1, vector<int>(n + 1, 0));
  for (int i = 1; i <= n; i++) {
    ret[i][0] = ret[i][i] = 1;
    for (int j = 1; j < i; j++) {
      ret[i][j] = ret[i - 1][j] + ret[i - 1][j - 1];
    }
  }
}
int toInt(string s) {
  int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
long long int toLInt(string s) {
  long long int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
vector<string> parse(string temp) {
  vector<string> ans;
  ans.clear();
  string s;
  istringstream iss(temp);
  while (iss >> s) ans.push_back(s);
  return ans;
}
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <class T>
inline T power(T b, T p) {
  if (p < 0) return -1;
  if (b <= 0) return -2;
  if (!p) return 1;
  return b * power(b, p - 1);
}
template <class T>
inline int asd(T &ret) {
  char r;
  bool start = false, neg = false;
  ret = 0;
  bool isaNumber = false;
  while (true) {
    r = getchar();
    if (r == EOF) {
      return 0;
    }
    if ((r - '0' < 0 || r - '0' > 9) && r != '-' && !start) {
      continue;
    }
    if ((r - '0' < 0 || r - '0' > 9) && r != '-' && start) {
      break;
    }
    if (start) ret *= 10;
    start = true;
    if (r == '-')
      neg = true;
    else
      ret += r - '0';
  }
  if (neg) ret *= -1;
  return 1;
}
template <class T>
inline int asd(T &ret1, T &ret2) {
  asd(ret1);
  asd(ret2);
}
template <class T>
inline int asd(T &ret1, T &ret2, T &ret3) {
  asd(ret1, ret2);
  asd(ret3);
}
template <class T>
inline int asd(T &ret1, T &ret2, T &ret3, T &ret4) {
  asd(ret1, ret2);
  asd(ret3, ret4);
}
template <class T>
inline void asdasd(T x, char y) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  char buf[21], *p = buf;
  do {
    *p++ = '0' + x % 10;
    x /= 10;
  } while (x);
  do {
    putchar(*--p);
  } while (p > buf);
  if (y == 0)
    putchar('\n');
  else if (y == 1)
    putchar(' ');
}
template <typename value_type>
istream &operator>>(istream &in, vector<value_type> &a) {
  if (!a.size()) {
    size_t n;
    asd(n);
    a.resize(n);
  }
  for (typename vector<value_type>::iterator iter = a.begin(); iter != a.end();
       ++iter)
    asd(*iter);
  return in;
}
template <typename value_type>
ostream &operator<<(ostream &out, const vector<value_type> &a) {
  int sz = a.size();
  for (int i = (int)(0); i <= (int)(sz - 1); i++) asdasd(a[i], i != sz);
  return out;
}
template <typename value_type>
ostream &operator<<(ostream &out, const vector<vector<value_type> > &a) {
  int sza = a.size();
  int szb = a[0].size();
  for (int i = (int)(0); i <= (int)(sza - 1); i++) {
    for (int j = (int)(0); j <= (int)(szb - 1); j++) asdasd(a[i][j], j != sza);
    puts("");
  }
  return out;
}
template <typename value_type>
ostream &operator<<(ostream &out, const set<value_type> &a) {
  for (__typeof(a.begin()) e = a.begin(); e != a.end(); ++e)
    asdasd(*e, e != a.end());
  return out;
}
template <typename key_type, typename value_type>
ostream &operator<<(ostream &in, map<key_type, value_type> &a) {
  for (__typeof(a.begin()) e = a.begin(); e != a.end(); ++e) {
    cout << (*e).first << " -> " << (*e).second << endl;
  }
  return in;
}
template <typename key_type, typename value_type>
istream &operator>>(istream &in, pair<key_type, value_type> &p) {
  in >> p.first >> p.second;
  return in;
}
template <typename key_type, typename value_type>
ostream &operator<<(ostream &out, const pair<key_type, value_type> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}
vector<int> inverseArray(int n, int m) {
  vector<int> modI(n + 1, 0);
  modI[1] = 1;
  for (int i = 2; i <= n; i++) {
    modI[i] = (-(m / i) * modI[m % i]) % m + m;
  }
  return modI;
}
pair<long long int, pair<long long int, long long int> > extendedEuclid(
    long long int a, long long int b) {
  long long int x = 1, y = 0;
  long long int xLast = 0, yLast = 1;
  long long int q, r, m, n;
  while (a != 0) {
    q = b / a;
    r = b % a;
    m = xLast - q * x;
    n = yLast - q * y;
    xLast = x, yLast = y;
    x = m, y = n;
    b = a, a = r;
  }
  return make_pair(b, make_pair(xLast, yLast));
}
long long int modInverse(long long int a, long long int m) {
  return (extendedEuclid(a, m).second.first + m) % m;
}
bool last[1000001], Set[1000001];
int p[1000001], q[1000001], res[200001];
int main() {
  int n;
  asd(n);
  int a, b;
  for (int i = (int)(0); i <= (int)(n - 1); i++) {
    asd(a);
    asd(b);
    p[a] = b;
    last[b] = 1;
    Set[a] = 1;
    Set[b] = 1;
  }
  int st;
  for (int i = (int)(1); i <= (int)(1000000); i++) {
    if (Set[i] && !last[i]) {
      st = i;
      break;
    }
  }
  for (int i = 1; i <= n; i += 2) {
    res[i] = st;
    st = p[st];
  }
  st = p[0];
  for (int i = 2; i <= n; i += 2) {
    res[i] = st;
    st = p[st];
  }
  for (int i = (int)(1); i <= (int)(n); i++) {
    asdasd(res[i], i != n);
  }
  return 0;
}