#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;
}