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

#define V_NUM 10000
#define E_NUM 100000

struct node {
  int state;
};

struct node vertex[V_NUM];
int M[V_NUM][V_NUM];
int N;

void init(){
int i ,j;
  for(i = 0 ; i < V_NUM; i++){
    for(j = 0 ; j < V_NUM; j++){
      if(i == j){
	M[i][j] =1;
      }else{
	M[i][j] = 0;
      }
    }
  }
}

void visit(int v){
  vertex[v].state = 1;  
int z;
  for(z = 0; z < N ; z++){
    //printf("M[%d][%d]:%d , vetex[%d]:%d\n",v,z,M[v][z],z,vertex[z].state);
    if(M[v][z] && (vertex[z].state) == 0){
      visit(z);
    }
  }
  printf("%d\n",v);
}

void printMap(){
int i,j;
  for(i = 0 ; i < V_NUM; i++){
    for(j = 0 ; j < V_NUM; j++){
      printf("%d ", M[i][j]);
    }
    printf("\n");
  }
}

void print(){
  for(int i =0; i < N; i++){
    printf("%d ", vertex[i].state);
  }
  printf("\n");
}

int main(void){
  int v=0;
  int e=0;
  scanf("%d %d",&v,&e);
  N = v;
  init();
int i ;
  for(i = 0 ; i < v; i++){
    int a, b;
    scanf("%d %d", &a, &b);
    M[a][b] = 1;
    vertex[i].state = 0;
  }
  //print();
  for(i = 0 ; i < N; i++){
    if(vertex[i].state == 0){
      visit(i);
    }
  }

  return 1;
}