import Control.Monad (replicateM,forM_)
import Data.Array (Array, assocs, accum, (!))
import Data.List (partition)
import qualified Data.Array.ST as STArr

type Wins = Array Int [Int]
type LoseCounts = Array Int Int

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 = groups `seq` (concat groups, all (==1) $ map length groups)
    where
    groups = wins' `seq` lcs `seq` solve' wins' [1..n] lcs []
    wins' = wins n rels
    lcs = loseCounts n rels

    solve' _ [] _ acc = reverse acc
    solve' wins ns lcs acc = ns' `seq` lcs' `seq` nolose `seq`
                             solve' wins ns' lcs' (nolose:acc)
        where
        (nolose,ns') = partition (\n -> lcs!n == 0) ns
        lcs' = foldr decl lcs nolose
        decl n lcs = accum (-) lcs [(i,1)|i<-wins!n]

wins :: Int -> [(Int,Int)] -> Wins
wins n rels = STArr.runSTArray $ do
    arr <- STArr.newArray (1,n) []
    forM_ rels (update arr)
    return arr
    where
    update arr (a,b) = do
        bs <- STArr.readArray arr a
        STArr.writeArray arr a (b:bs)

loseCounts :: Int -> [(Int,Int)] -> LoseCounts
loseCounts n rels = STArr.runSTArray $ do
    arr <- STArr.newArray (1,n) 0
    forM_ rels (update arr)
    return arr
    where
    update arr (_,b) = do
        c <- STArr.readArray arr b
        STArr.writeArray arr b (c+1)