import sys

def henkan(l1):
  maped_num = map(str,l1)
  s=''.join(maped_num)
  return s


keta,num = map(int,input().rstrip().split())
l=[]

if num ==0:
  print(num)
  sys.exit()
  
  
for i in range(keta):
  l.append("#")
  

for i in range(num):
    a,b = map(int,input().rstrip().split())
    a=a-1
    if l[a]=="#":
      l[a]=b 
    elif l[a] > b:
      l[a]=b     


      
if l[0] == "#":
  print("-1")
elif l[0] == 0:
  print("-1")
elif l[1]=="#":
  l[1]=0
  x=henkan(l)
  print(x)
elif l[2]=="#":
  l[2]=0
  x=henkan(l)
  print(x)
else:
  x=henkan(l)
  print(x)

  
  

  

