n, m = map(int, input().split())
sc = {1:set(), 2:set(), 3:set()}
#print(sc)

for i in range(m):
  s, c = map(int, input().split())
  sc[s].add(c)

ans = 0
#print(sc)
#重複してるか
for v in sc.values():
  if len(v) > 1:
    ans = -1
if ans != -1:
  if sc[1] == {0}:
    ans = -1
  elif (sc[1] == {0}) and (sc[2] == {0}):
    ans = -1
  else:
    ans = ""
    if sc[1] != set():
        ans += str(sc[1].pop())
    else:
        ans += str("1")
    if sc[2] != set():
        ans += str(sc[2].pop())
    else:
        ans += str("0")
    if sc[3] != set():
      ans += str(sc[3].pop())
    else:
      ans += str("0")

print(ans)


    