n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]


num=[-1]*n

for i in l:
  if num[i[0]-1]==-1 or num[i[0]-1]==i[1]:
    num[i[0]-1]=i[1]
  elif i[0]==1 and i[1]==0 and n==1:
    print(0)
    exit()
  else:
    print(-1)
    exit()
    
if num[0]==0:
  print(-1)
elif n==1 and num[0]==-1:
  print(0)
else:
  for i in range(len(num)):
    if num[i]==-1 and i==0:
      num[i]=1
    elif num[i]==-1:
      num[i]=0
    
  print(*num,sep='')
    
    
