n,m=map(int,input().split())
digits=[0]*n
f=True
for i in range(m):
  s,c=[int(x) for x in input().split()]
  s-=1
  if s==0 and c==0:
    f=False
    break
  elif digits[s]!=0 and digits[s]!=c:
    f=False
    break
  else:
    digits[s]=c

if f:
  ans=""
  for i in range(n):
    if i==0 and digits[i]==0:
      ans+="1"
    else:
      ans+=str(digits[i])
  print(int(ans))
else:
  print(-1)
