#include<iostream>
using namespace std;
int main()
{
	int num[1005] = {};
	int find_first[1005] = {};

	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		int x, next;
		cin >> x >> next;
		num[x] = next;
		find_first[x] += 1;
		if(next!=-1) find_first[next] += 1;
	}
	int first;
	for(int i = 0; i < 1001; i++)
	{
		if(find_first[i] == 1)
		{
			first = i;
			break;
		}
	}
	cout << first;

	int next = num[first];
	while(next != -1)
	{
		cout << " " << next;
		next = num[next];
	}
	cout << endl;

}
