n,m = [int(i) for i in input().split()]
a = []
b = []
to = [10,10,10]
 
for i in range(m):
  s,c = [int(j) for j in input().split()]
  a.append(s)
  b.append(c)
  
for i in range(m):
  if 3 == a[i]:
    to[2] = b[i]
  elif 2 == a[i]:
    to[1] = b[i]
  elif 1 == a[i]:
    to[0] = b[i]
    
if to.count(10) == 2:
  print(-1)
  exit()
  
for i in range(3):
  if to[i] == 10:
    to[i] = 0
    
if to[0] == 0 and n == 3:
  to[0] = 1
elif to[1] == 0 and n == 2:
  to[1] = 1
  
total = to[0] * 100 + to[1] * 10 + to[2]
print(total)