1. 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* Problem: 10305 - Ordering Tasks
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1246
*
* @author Burgmair Stefan
* @author YYY
* @version 1.0, 05/05/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.144
*/

public class Main
{
static int nmbrOfTasks;
static boolean [][] successors;
static ArrayList<Integer> elements = new ArrayList<Integer> ();

public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int nmbrOfRelations;
String [] arr;
int [] precursor;

do{
arr = reader.readLine().split(" ");
nmbrOfTasks = Integer.parseInt(arr[0]);
nmbrOfRelations = Integer.parseInt(arr[1]);
successors = new boolean [nmbrOfTasks][nmbrOfTasks];
precursor = new int [nmbrOfTasks];

for(int i = 0; i < nmbrOfTasks; i++){
precursor [i] = 0;
elements.add(i);
for(int j = 0; j < nmbrOfTasks; j++){
successors [i][j] = false;

}
}

if (nmbrOfTasks != 0 || nmbrOfRelations != 0){
for (int i = 0; i < nmbrOfRelations; i ++){
arr = reader.readLine().split(" ");
successors [Integer.parseInt(arr[0])-1][Integer.parseInt(arr[1])-1] = true;
precursor [Integer.parseInt(arr[1]) - 1] = precursor [Integer.parseInt(arr[1]) - 1] + 1;
}
//printMap(successors);
while(elements.isEmpty() == false){
for (int i = 0; i < elements.size(); i ++){
if (precursor[elements.get(i)] == 0){
System.out.print(elements.get(i)+1 + " ");
//Gehe die Liste der Nachfolger des gefundenen Elements durch und verringere die Vorgängeranzahl um 1.
for (int j = 0; j < nmbrOfTasks; j ++){
if(successors [elements.get(i)][j] == true){
precursor[j] = precursor[j] - 1;
}
}
elements.remove(i);
break;
}
}
}
System.out.println();
}
}while (reader.ready());
}
}