let n, m = stdin.ReadLine().Split() |> fun array -> int array.[0], int array.[1]
let scPairs = [|
        for _ in 1.. m do
            yield stdin.ReadLine().Split() |> fun array -> int array.[0], int array.[1]
    |]

let predicateDetail num (s,c) = 
    (string num).ToCharArray() |> fun array ->
        (
            if s >= array.Length + 1 then false
            elif array.[s-1] <> char (string c) then false
            else true
        )

let predicate num =
    scPairs 
    |> Seq.forall (predicateDetail num) 

[pown 10 (n-1)..999]
|> Seq.tryFind (fun num -> predicate num)
|> function
| Some(v) -> v
| None -> -1
|> stdout.WriteLine
