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)
    dim dummy(n-1) as char
    for i=0 to n-1
      dummy(i) = " "c
    next
    if m=0 then dummy(n-1)="0"c
    for i=1 to m
      arr = split(console.readline())
      s=arr(0):c=arr(1)
      if dummy(s-1) = " "c then
        dummy(s-1)=c
      else if dummy(s-1)<>c then
        console.writeline("-1")
        return
      end if
    next
    if (n=2 andalso dummy(0)=" "c andalso dummy(1)=" "c) orelse _
      (n=3 andalso dummy(0)=" "c andalso dummy(1)=" "c andalso dummy(2)=" "c) then
      dummy(n-1)="1"c
	end if
    if dummy(0)=" "c then dummy(0)="1"c
	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