open System

// input
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

// utils

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inline flip f a b = f b a  

// memoization
let inline memo size f =
  let dp = Array.create size None
  let rec g x =
    match dp.[x] with
    | None ->
      let v = f g x
      dp.[x] <- Some v
      v
    | Some v -> v
  g

let inline memo2 size1 size2 f =
  let dp = Array2D.create size1 size2 None
  let rec g x y =
    match Array2D.get dp x y with
    | None ->
      let v = f g x y
      Array2D.set dp x y (Some v)
      v
    | Some v -> v
  g

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

let N, M = readInts() |> pair
let sc = [| for _ in 1..M -> readInts() |> pair |]

let keta s n = (n / (pown 10 (N-s))) % 10
let pred n = Array.forall (fun (s, c) -> (keta s n) = c) sc

seq { (pown 10 (N-1))..((pown 10 N)-1) }
|> Seq.tryFind pred
|> Option.getOr -1
|> printfn "%d"
