import sys
input = sys.stdin.readlines()
N = ["" for i in range(int(input[0][0]))]
ss = []
cs = []
scs = [line.split(" ") for line in input[1:]]
for sc in scs:
    if not N[int(sc[0])-1]:
        N[int(sc[0])-1] = sc[1].strip()
    elif N[int(sc[0])-1] == sc[1].strip():
        pass
    else:
        print(-1)
        sys.exit()

answer = ["" for i in range(int(input[0][0]))]
for idx, n in enumerate(N):
    if n == "":
        answer[idx] = "0"
    else:
        answer[idx] = n

answer = "".join(answer)
if str(int(answer)) != answer:
    print(-1)
else:
    print(answer)
