import Control.Monad (replicateM,forM_)
import Data.List (partition)
import qualified Data.Set as Set

main = do
    n <- readLn
    m <- readLn
    rels <- replicateM m (getLine >>= return . relation . map read . words)

    let
        (sorted,fixed) = solve n rels

    forM_ sorted print
    print (if fixed then 0 else 1)

    where
    relation [a,b] = (a,b)

solve :: Int -> [(Int,Int)] -> ([Int],Bool)
solve n rels = (sorted,fixed)
    where
    sorted = concat groups
    fixed = all (==1) $ map length groups

    groups :: [[Int]]
    groups = solve' [1..n] rels

    solve' [] rels = []
    solve' ns rels = noloses : solve' ns' rels'
        where
        (ns',noloses) = partition (`Set.member` losers) ns
        rels' = filter ((`Set.member` losers) . fst) rels
        losers = foldr Set.insert Set.empty (map snd rels)