import sys
N, M = map(int, sys.stdin.readline().split())
scList = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
h = []
t = []
o = []
flag = False
for sc in scList:
  [s, c] = sc
  if s == 1 and c == 0:
    flag = True
  if N+1 - s == 1:
    o.append(c)
  elif N+1 - s == 2:
    t.append(c)
  else:
    h.append(c)
if len(h) >= 2 or len(t) >= 2 or len(o) >= 2 or flag:
  print(-1)
else:
  print(h*100 + t*10 + o)