#include <bits/stdc++.h> #define endl "\n" #define ll long long #define loop(i, n) for(int i = 0; i <n;++i) #define INF 987654321 #define MAX 32000 + 1 using namespace std; int n, m; vector<int> graph[MAX]; int indegree[MAX] = { 0, }; vector<int> topologySort() { queue<int> q; vector<int> ans; for (int i = 1; i <= n; ++i) if (indegree[i] == 0) q.push(i); while (!q.empty()) { int now = q.front(); q.pop(); ans.push_back(now); for (int i : graph[now]) { indegree[i] -= 1; //진입차수가 0이면queue에 push if (indegree[i] == 0) q.push(i); } } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; graph[a].push_back(b); //진입차수 증가 indegree[b]++; } vector<int> ans = topologySort(); if (!ans.empty()) for (int i : ans) cout << i << " "; return 0; }