import strutils,sequtils
import algorithm,sets,lists,critbits,sequtils,intsets,strutils,tables,math,heapqueue,future

let read = iterator: string {.closure.} =
  while true:
    for s in stdin.readLine.split:
      yield s

let N, M = read().parseInt

var s = (1..N).mapIt(-1)
for _ in 1..M:
  let d, c = read().parseInt
  if s[d-1] != -1 and s[d-1] != c:
    echo -1
    quit()
  s[d-1] = c

if s[0] == 0:
  echo -1
  quit()
if s[0] == -1:
  s[0] = 1
echo s.mapIt(max(it, 0)).mapIt($it).join("")
