n,m=map(int,input().split())
l=[]
for i in range(m):
  s,c=map(int,input().split())
  l.append((s-1,str(c)))
for i in range(1000):
  d=list(str(i))
  if len(d)!=n:continue
  for j in l:
    if d[j[0]]!=j[1]:break
  else:
    print(i)
    break
else:
  print(-1)
    
