let  [|N; M|] = stdin.ReadLine().Split(' ') |> Array.map int

let mutable (b:bool[]) = [|for i in 0 .. N -> false|]
let mutable a = [|0 .. N|]
let mutable m = false
 
for i in 1 .. M do
    let [|s; c|] = stdin.ReadLine().Split(' ') |> Array.map int
    if b.[s] = false 
        then
            b.[s] <- true
            a.[s] <- c
        else if a.[s] <> c 
            then
                m <- true

let rec p a (b:int) =
    if b = 0 then 1
    else 
        let c = b - 1
        a * p a c


             
if m = true then
        printf "%d" -1
    else
        let mutable ans = ""
        for i in 1 .. N do 
            let j =
                if b.[i] = true 
                    then a.[i] 
                    else if i <> N then
                        0
                        else 1         
            ans <- ans + j.ToString()
        printf "%s" ans

