#include<stdio.h>
#include<stdlib.h>

struct node {
  int id;
  struct node *next;
};

struct node **list;
int *indeg, *visit, *stack, sp;
void Insert(int, int);
void bfs(int, int);
int main(void)
{
  int i, v, e, s, t;
  scanf("%d %d", &v, &e);
  list = (struct node**)malloc(sizeof(struct node*) * v);
  indeg = (int*)calloc(v, sizeof(int));
  visit = (int*)calloc(v, sizeof(int));
  stack = (int*)malloc(sizeof(int) * v);
  for (i = 0; i < v; i++) list[i] = NULL;
  for (i = 0; i < e; i++) {
    scanf("%d %d", &s, &t);
    Insert(s, t);
  }
  for (i = 0; i < v; i++) {
    struct node *n;
    for (n = list[i]; n != NULL; n = n->next) indeg[n->id]++;
  }
  for (i = 0; i < v; i++) {
    if (!(indeg[i] || visit[i])) bfs(i, v);
  }
  for (i = 0; i < sp; i++) printf("%d\n", stack[i]);
  for (i = 0; i < v; i++) free(list[i]);
  free(list);
  free(indeg);
  free(visit);
  free(stack);
}
void Insert(int a, int b)
{
  struct node *p = (struct node*)malloc(sizeof(struct node));
  p->id = b;
  p->next=list[a];
  list[a] = p;
}
void bfs(int point, int size)
{
  int ptr_front = 0, ptr_back = 0, *queue = (int*)malloc(sizeof(int) * size);
  queue[ptr_back++] = point;
  visit[point] = 1;
  while (ptr_front != ptr_back) {
    int u = queue[ptr_front++];
    struct node *n;
    stack[sp++] = u;
    for (n = list[u]; n != NULL; n = n->next) {
      indeg[n->id]--;
      if (!(indeg[n->id] || visit[n->id])) {
        visit[n->id] = 1;
        queue[ptr_back++] = n->id;
      }
    }
  }
  free(queue);
}
