import sys
n,m=map(int,input().split())
if m==0:
  if n==1:
    print(0)
  elif n==2:
    print(10)
  elif n==3:
    print(100)
  sys.exit()
A=[0]*n
B=[[0]*2 for i in range(m)]
for i in range(m):
  B[i]=list(map(int,input().split()))
B.sort()
if n!=1 and B[0]==[1,0]:
  print(-1)
  sys.exit()
for i in range(m-1):
  if B[i][0]==B[i+1][0]:
    if B[i][1]!=B[i+1][1]:
      print(-1)
      sys.exit()
for i in range(m):
  A[B[i][0]-1]=B[i][1]
if A[0]==0:
  A[0]=1
ans=0
for i in range(n):
  ans=ans+A[i]*10**(n-i-1)
print(ans)