n,m=(int(i) for i in input().split())
l=[None,None,None]
answer='unknown'
for i in range(m):
  a,b=(int(i) for i in input().split())
  if l[n-a]==None:
    l[n-a]=b
  elif l[n-a]!=b:
    answer='-1'
    break
for i in range(3):
  if l[i]==None:
    if i!=n-1:
      l[i]=0
    else:
      l[i]=1
r=l[2]*10**2+l[1]*10+l[0]
if len(str(r))!=n:
  answer='-1'
if answer=='-1':
  print('-1')
else:
  print(r)