

keta,num = map(int,input().rstrip().split())
l=[]
for i in range(keta):
  l.append(0)
  

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

      
if l[0]==0:
  if len(l)==1:
    print("0")
  else:
    print("-1")
else:
  maped_num = map(str,l)
  s=''.join(maped_num)
  print(s)