n1 = [int(str) for str in input().split()]
n = n1[0]
m = n1[1]
s1 = 0
s2 = 0
s3 = 0
if n == 1:
  o1 = 0
  o2 = 0
  o3 = 0
if n == 2:
  o1 = 0
  o2 = 1
  o3 = 0
if n == 3:
  o1 = 1
  o2 = 0
  o3 = 0
result = 0
  
for x in range(m):
  t = [int(s) for s in input().split()]
  s = t[0]
  c = t[1]
  
  if s == 1:
    if s1 == 0:
      o1 = c
      s1 += 1
    else:
      if c != o1:
        result = -1
  if s == 2:
    if s2 == 0:
      o2 = c
      s2 += 1
    else:
      if c != o2:
        result = -1
  if s == 3:
    if s3 == 0:
      o3 = c
      s3 += 1
    else:
      if c != o3:
        result = -1
  if result == -1:
    break
    
if result != -1:
  print(int(o1*100 + o2*10+o3))
else:
  print(-1)