#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
vector<int> toplogical;
void topSort(int node, vector<vector<int>> &graph, vector<bool> &visit){
for(int child: graph[node])
if(!visit[child]){
visit[child] = true;
topSort(child, graph, visit);
toplogical.push_back(child);
}
}
using namespace std;
int main(){
int nodes, egdes;
cin >> nodes >> egdes;
vector<vector<int>> graph(nodes+1);
vector<bool> visit(nodes+1);
int from, to;
while(egdes--){
cin >> from >> to;
graph[from].push_back(to);
}
// Show Graph
cout << endl ;
for(int node = 1; node <= nodes; node++){
cout << node <<" : ";
for(int child: graph[node])
cout << child <<' ';
cout << endl;
}
// dfs
cout << endl;
for(int node = 1; node <= nodes; node++)
if(!visit[node]){
visit[node] = true;
topSort(node, graph, visit);
toplogical.push_back(node);
}
// Topological Sort
reverse(toplogical.begin(), toplogical.end());
cout << endl;
for(int node: toplogical)
cout << node << ' ';
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bWFwPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp2ZWN0b3I8aW50PiB0b3Bsb2dpY2FsOwp2b2lkIHRvcFNvcnQoaW50IG5vZGUsIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gJmdyYXBoLCB2ZWN0b3I8Ym9vbD4gJnZpc2l0KXsKICAgIGZvcihpbnQgY2hpbGQ6IGdyYXBoW25vZGVdKQogICAgICAgIGlmKCF2aXNpdFtjaGlsZF0pewogICAgICAgICAgICB2aXNpdFtjaGlsZF0gPSB0cnVlOwogICAgICAgICAgICB0b3BTb3J0KGNoaWxkLCBncmFwaCwgdmlzaXQpOwogICAgICAgICAgICB0b3Bsb2dpY2FsLnB1c2hfYmFjayhjaGlsZCk7CiAgICAgICAgfQp9Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKXsKCiAgICBpbnQgbm9kZXMsIGVnZGVzOwogICA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