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 "3" in d:
  c = d["3"]
else:
  c = "0"
if "2" in d:
  b = d["2"]
else:
  b = "0"
if "1" in d:
  a = d["1"]
  if a + b + c == "000":
    print("-1")
  else:
    print(a + b + c)
else:
  if b + c == "00":
    print("-1")
  else:
    print(b + c)