N,M=map(int,input().split())
n=int(N)
m=int(M)
numlist=[0,0,0]
answer=0
for i in range(m):
  s,c=map(int,input().split())
  s=int(s)
  c=int(c)
  if s==4-n and c==0:
    answer=-1
  elif numlist[s-1]!=0 and numlist[s-1]!=c:
    answer=-1
    break
  else:
    numlist[s-1]=c
if answer==-1:
  print(answer)
else:
  if numlist[3-n]==0:
    numlist[3-n]=1
  answer=numlist[0]*10**2+numlist[1]*10+numlist[2]
  print(answer)