N , M = map(int,input().split())
sc = list(tuple(map(int,input().split())) for _ in range(M))
sc = list(set(sc))
sc.sort()
# print(sc)
if len(sc) > 3:
    print("-1")
    exit()

num = ["-1"] * 3

for s, c in sc:
    num[s - 1] = str(c)

for i in range(3):
    if num[i] == "-1":
        num[i] = "0"

for i in range(2):
    if num[0] == "0":
        num.pop(0)
    else:
        break


if len(num) == N:
    print("".join(num))
else:
    print("-1")
