n,m=map(int,input().split())
l=[-1]*n
for i in range(m):
  a,b=map(int,input().split())
  if l[a-1]>-1 and l[a-1]==b:
    pass
  elif l[a-1]>-1 and l[a-1]!=b:
    print(-1)
    quit()
  else:
    l[a-1]=b
for i in range(n):
  if l[i]<0:
    l[i]=0
if l[0]==0 and n>1:
  print(-1)
else:
  a=0
  for i in range(n):
    a+=(10**i)*l[-i-1]
  print(a)