n, m = list(map(int, input().split(" ")))

def clc(m):
  s_c = {}
  for _ in range(m):
    s, c = list(map(int, input().split(" ")))
    if c == 0:
      if n in (2, 3) and s == 1:
        return -1
    if s not in s_c:
      s_c[s] = c
    else:
      if s_c[s] != c:
        return -1
  number = [0 for _ in range(n)]

  for i in range(n):
    j = i + 1
    if j in s_c:
      number[i] = s_c[j]
  return "".join(map(str, number))
r = clc(m)
if r == -1:
  print(-1)
else:
  print(r)
  