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

num = ["x"] * n

for _ in range(m):
  s, c = map(int, input().split())
  if num[s - 1] == "x":
    num[s - 1] = str(c)
  elif num[s - 1] != str(c):
    print("-1")
    exit()

if num == ["0"]:
  print("0")
elif num[0] == "0":
  print("-1")
else:
  if num[0] == "x":
    num[0] = "1"
  print("".join([s.replace("x","0") for s in num]))