1. JAVA, Simon Baumgartner


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.BitSet;
import java.util.LinkedList;

/*
* ACM Programming Contest
* Problem: 10305 Ordering Tasks
* Status: Accepted
* Runtime: 0.112
* Date: 2009-06-08
* Author: Simon Baumgartner
*
*/

public class Main {

public static void main(String[] args) throws IOException {

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// BufferedReader in = new BufferedReader(new FileReader("input.txt"));
String[] tokens = in.readLine().split(" ");
int numberOfTasks = Integer.parseInt(tokens[0]);
int numberOfRelations = Integer.parseInt(tokens[1]);
while(numberOfRelations != 0 || numberOfTasks != 0){
//build bitsets
BitSet[] bitSets = new BitSet[numberOfTasks];

for (int i = 0; i < numberOfTasks; i++) {
bitSets[i] = new BitSet();
}
for (int i = 0; i < numberOfRelations; i++) {
tokens = in.readLine().split(" ");
int pre = Integer.parseInt(tokens[0]) - 1;
int task = Integer.parseInt(tokens[1]) - 1;
bitSets[task].set(pre);
}
LinkedList<Integer> ret = new LinkedList<Integer>();
while(ret.size() != numberOfTasks){
LinkedList<Integer> eraseIndexes = new LinkedList<Integer>();
for (int i = 0; i < bitSets.length; i++) {
BitSet bitSet = bitSets[i];
if(bitSet == null)
continue;
if(bitSet.cardinality() == 0){
ret.add(i+1);
eraseIndexes.add(i);
}
}
for (int i = 0; i < eraseIndexes.size(); i++) {
int index = eraseIndexes.get(i);
for (BitSet b : bitSets) {
if(b == null)
continue;
b.set(index, false);
}
bitSets[index] = null;
}
}
for (int i = 0; i < ret.size(); i++) {
System.out.print(ret.get(i) + " ");
}
System.out.println();

tokens = in.readLine().split(" ");
numberOfTasks = Integer.parseInt(tokens[0]);
numberOfRelations = Integer.parseInt(tokens[1]);
}
}

}