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