n,m=map(int,input().split(" "))
a=0

if n==1:
  if m==0:
    print(0)
  if m==1:
    k,num=map(int,input().split(" "))
    if k==1:
      print(num)
    else:
      print(-1)
else:
  if m==0:
    print(10**(n-1))
  else:
    B=[0 for i in range(m)]
    for i in range(m):
      k,num=map(int,input().split(" "))
      if k-1==0 and num==0:
        a=1
        break
      if B[k-1]!=num and B[k-1]!=0:
        a=1
        break
      else:
        B[k-1]=num
  if a==1:
    print(-1)
  else:
    if B[0]==0:
      B[0]=1
    for i in range(m):
      print(B[i],end="")