import sys
n,m=map(int,input().split())
d={}
for i in range(m):
  s,c=map(int,input().split())
  if s not in d:
    d.setdefault(s,c)
    continue
    
  else:
    if d[s]==c:
      continue
    else:
      print(-1)
      sys.exit()
      
    
z=[0]*n
for i in d.keys():
  z[i-1]=d[i]
  if z[0]==0:
    if z==[0]*n:
      print(0)
      sys.exit()
    else:
      print(-1)
      sys.exit()


for i in z:
  print(i,end='')
print()