n,m=map(int,input().split())
if m!=0:
  p=0
  a=[-1 for s in range(n)]
  for i in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0:
      p+=1
      break
    elif a[s-1]==-1 or a[s-1]==c:
      a[s-1]=c
    else:
      p+=1
      break

  if p==0:
    num=0
    for i,j in enumerate(reversed(a)):
      if j == -1 and i+1 ==len(a):
        j=1
      elif j == -1:
        j=0
      num += j*(10**i)
    print(num)
  else:
    print(-1)
else:
  if n==1:
    print(0)
  elif n ==2:
    print(10)
  else:
    print(100)