result = 0
n,m = input().split(' ')
n = int(n)
m = int(m)
x = -1
y = -1
z = -1
 
if result != -1:

  for i in range(m):
    s, c = input().split(" ")
    s = int(s)
    c = int(c)
    if s == 1 :
      if x != -1 and x != c:
        result = -1
        break
      x = c
    
    elif s == 2:
      if y != -1 and y != c:
        result = -1
        break
      y = c
    
    elif s == 3:
      if z != -1 and z != c:
        result = -1
        break
      z = c
      
if result == -1:
  print(-1)
else:
  if x == -1:
    x = 1
  if y == -1:
    y = 0
  if z == -1:
    z = 0
  print(100*x + 10*y + z)
    
  