#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int v = 6; // number of vertices
vector <vector<int>> adjecancy(v + 1); // adjecncy list of the graph
void addEdge(int x,int y) //add edge to the graph
{
adjecancy[x].push_back(y);
//adjecancy[y].push_back(x);
}
vector <bool> visited(v + 1);
vector <pair<int, int>> departureSorted(v+1);
int t = 0;
void topSort(int v)
{
visited[v] = true;
for (int i : adjecancy[v])
{
if (!visited[i])
topSort(i);
}
departureSorted[v] = { ++t, v };
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
int x, y;
map <int, int> parent;
while (n--)
{
cin >> x >> y;
addEdge(x, y);
}
topSort(1);
//display vectices in topological ordering
sort(departureSorted.begin(), departureSorted.end());
for (int i = departureSorted.size()-1; i >= 1; i--)
cout << departureSorted[i].second << " ";
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IHYgPSA2OyAvLyBudW1iZXIgb2YgdmVydGljZXMKdmVjdG9yIDx2ZWN0b3I8aW50Pj4gYWRqZWNhbmN5KHYgKyAxKTsgLy8gYWRqZWNuY3kgbGlzdCBvZiB0aGUgZ3JhcGgKCnZvaWQgYWRkRWRnZShpbnQgeCxpbnQgeSkgLy9hZGQgZWRnZSB0byB0aGUgZ3JhcGgKewoJYWRqZWNhbmN5W3hdLnB1c2hfYmFjayh5KTsKCS8vYWRqZWNhbmN5W3ldLnB1c2hfYmFjayh4KTsKfQoKdmVjdG9yIDxib29sPiB2aXNpdGVkKHYgKyAxKTsKdmVjdG9yIDxwYWlyPGludCwgaW50Pj4gZGVwYXJ0dXJlU29ydGVkKHYrMSk7CmludCB0ID0gMDsKCnZvaWQgdG9wU29ydChpbnQgdikKewoJdmlzaXRlZFt2XSA9IHRydWU7CgoJZm9yIChpbnQgaSA6I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