import Control.Monad
import Data.List
import qualified Data.Map as M

listToTupple :: [Int] -> (Int, [Int])
listToTupple = \[x,y] -> (x,[y])

solve :: [Int] -> String
solve temp 
 | -1 `elem` temp = "-1"
 | otherwise      = concat $ map show temp

solve' :: String -> String
solve' input
 | input == "0"      = "0"
 | head input == '0' = "-1"
 | otherwise         = input

main = do
 [n,m] <- map read . words <$> getLine :: IO[Int]
 inData <- replicateM m (listToTupple . map read . words <$> getLine) :: IO [(Int, [Int])]
 let zeroData = M.fromList $ zip [1..n] $ repeat [0]
 let temp = M.toList $ M.map (\x -> if (length x) > 1 then -1 else head x) $ M.union (M.map nub $ M.fromListWith (++) inData) zeroData
 putStr $ solve' $ solve (map snd temp) 