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

if result != -1:
  for i in range(m):
    s, c = input().split(" ")
    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:
  print(100*x + 10*y + z)
    
  