#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <queue>
using namespace std;
const int maxn = 10010;
int indegree[maxn]={0};
vector<int> g[maxn],print;
int n,m;
bool tologicalSort(){
int count=0;
queue<int> q;
for(int i=0;i<n;i++){
if(indegree[i]==0){
q.push(i);
}
}
while(!q.empty()){
int u = q.front();
q.pop();
for(int i=0;i<g[u].size();i++){
int v=g[u][i];
indegree[v]--;
if(indegree[v]==0){
q.push(v);
}
}
print.push_back(u);
count++;
}
if(count==n) return true;
else return false;
}
int main()
{
scanf("%d%d",&n,&m);
print.clear();
for(int i=0;i<m;i++){
int a,b;
scanf("%d%d",&a,&b);
g[a].push_back(b);
indegree[b]++;
}
bool istol = tologicalSort();
for(int i=0;i<print.size();i++){
printf("%d ",print[i]);
}
return 0;
}