Module C
  Sub Main(ByVal args() As String)
    dim arr() as string = split(console.readline())
    dim n,m,i,s as integer
    dim c as char
    n=arr(0):m=arr(1)
    if m=0 then
      if n=1 then
        console.writeline("0")
        return
      else if n=2 then
        console.writeline("10")
        return
      else
        console.writeline("100")
        return
      end if
    end if
    dim dummy(n-1) as char
    for i=0 to n-1
      dummy(i) = " "c
    next
    for i=1 to m
      arr = split(console.readline())
      s=arr(0):c=arr(1)
      if s<>n then
    	if c=" " then 
          console.writeline("-1")
          return
    	else if dummy(s-1) = " "c then
          dummy(s-1)=c
        else if dummy(s-1)<>c then
          console.writeline("-1")
          return
        end if
      else
        if dummy(s-1) = " "c then
        	dummy(s-1)=c
        else if dummy(s-1)<>c then
        	console.writeline("-1")
        	return
        end if 
      end if
    next
	for i=0 to n-1
  		dummy(i)=if(dummy(i)=" "c,"0"c,dummy(i))
    next
    dim result as string = new string(dummy)
    dim result_int as integer = integer.parse(result)
    console.writeline(if(result_int.tostring().length<n,"-1",result))
  End Sub
End Module