import strutils,sequtils
let
 nm=stdin.readline.split.map(parseInt)
 (n,m)=(nm[0],nm[1])
var
 number=repeat(-1,n)
 ok=0
for i in 1..m:
 let
  sc=stdin.readline.split.map(parseInt)
  (s,c)=(sc[0],sc[1])
 if number[s-1]== -1:
  number[s-1]=c
 elif number[s-1]!=c:
  echo -1
  quit()
for j,i in number: 
 if j<number.len-1:
  if i==0 and ok==0:
   echo -1
   quit()
  elif i== -1 and ok==0:
   ok=1
   stdout.write(1)
  else:
   ok=1
   if i== -1:
    stdout.write(0)
   else:
    stdout.write(i)
 else:
  stdout.write(i)