模板:
#include<bits/stdc++.h>
#define rint register int
#define deb(x) cerr<<#x<<" = "<<(x)<<'\n';
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
const ll mod = 1e9 + 7;
const int maxn = 3e5 + 10;
int n, m, cnt;
int in[maxn], tp[maxn];
vector <int> v[maxn];
void tp_sort(){
queue <int> Q;
for(int i=1; i<=n; i++)
if(!in[i]) Q.push(i);
while(!Q.empty()){
int q = Q.front();
Q.pop();
tp[cnt++] = q;
for(auto i : v[q]){
in[i]--;
if(!in[i]) Q.push(i);
}
}
}
int main() {
scanf("%d%d", &n, &m);
for(int i=0, x, y; i<m; i++){
scanf("%d%d", &x, &y);
v[x].push_back(y);
in[y]++;
}
tp_sort();
for(int i=0; i<cnt; i++)
printf("%d ", tp[i]);
}