n,m=map(int,input().split())
num=0
for _ in range(m):
  s,c = map(int,input().split())
  p=num//(10**(n-s))
  if p%10!=0 and p%10!=c:
    num=0
    break
  elif p%10==c:
    num=num
  else:
    num+=c*10**(n-s)
if num//10**(n-1)==0:
  print(-1)
else:
  print(num)

