import strutils, sequtils
let get = iterator: string {.closure.} =
  for s in stdin.readAll.split: yield s
let read = proc: int = get().parseInt
template rep(a, b: untyped):untyped = newSeqWith(b, a)

let n, m = read()
var sta = '0'.rep(n)
for i in 1..m:
  let s = read()
  let c = get()[0]
  if sta[s-1] != '0' and sta[s-1] != c:
    echo "-1"
    quit 0
  sta[s-1] = c

let ran = case n:
  of 1: toSeq(0..9)
  of 2: toSeq(10..99)
  of 3: toSeq(100..999)
  else: @[]

for n in ran:
  var f = true
  for i, c in $n:
    f = f and sta[i] == c
  if f:
    echo n
    quit 0

echo -1