N,K=[int(s) for s in input().split()]
ls=[-1 for _ in range(N+1)]
for _ in range(K):
  a,b=[int(s) for s in input().split()]
  if ls[a]==-1:
    ls[a]=b
  else:
    ls[0]=0
ans=0
if ls[0]==0:
  print(-1)
else:
  if N==1:
    ans=max([ls[1],0])    
  if N==2:
    for i in range(10,100):
      a=i//10
      b=i%10
      if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1):
        ans=i
        break
  if N==3:
    for i in range(100,1000):
      a=i//100
      b=(i//10)%10
      c=i%10
      if (a==ls[1] or ls[1]==-1) and (b==ls[2] or ls[2]==-1) and (c==ls[3] or ls[3]==-1):
        ans=i
        break
  print(ans)
