import sys
n,m=map(int,input().split())
l=[0]*n
o=0
for i in sys.stdin:
  s,c=map(int,i.split())
  if s==1 and c==0:
    o=-1
    break
  elif l[s-1]==0 or l[s-1]==c:
    l[s-1]=c
  else:
    o=-1
    break
if o==0:
  if l[0]==0:
    l[0]=1
  o=''.join([str(i) for i in l])
print(o)