import sys
N, M = map(int, input().split())
d = {}
for _ in range(M):
  s, c = input().split()
  if s in d and d[s] != c:
    print("-1")
    sys.exit()
  else:
    d[s] = c
if N == 3:
  if "1" in d and d["1"] == "0":
    print("-1")
    sys.exit()
  else:
    if "1" not in d:
      a = "1"
    else:
      a = d["1"]
    if "2" in d:
      b = d["2"]
    else:
      b = "0"
    if "3" in d:
      c = d["3"]
    else:
      c = "0"
  print(a + b + c)
  sys.exit()
  
if N == 2:
  if "2" in d and d["2"] == "0":
    print("-1")
    sys.exit()
  else:
    if "2" in d:
      b = d["2"]
    else:
      b = "1"
    if "3" in d:
      c = d["3"]
    else:
      c = "0"
  print(b + c)
  sys.exit()
  
if N == 1:
  if "3" in d and d["3"] == "0":
    print("-1")
    sys.exit()
  else:
    if "3" in d:
      c = d["3"]
    else:
      c = "1"
  print(c)