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

num = ["x"] * n

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

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