n,m = map(int,input().split())

ln = 10**10
a = [ln for _ in range(n)]
for _ in range(m):
  index, val = map(int,input().split())
  if a[index-1]> val:
    a[index-1]=val
zero=0;num=0;flag=0
for i in range(n):
  if a[i] == ln:
    a[i]=0
for i in range(n):
  if a[i]>0 and zero==0:
    num=1
    flag=1
    break
  else:
    zero=1
    
if flag==0:
  print("-1")
  
else:
  for i in a:
    print(i,end="")