n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
lis = [str(0)]*n
if n >= 2:
    lis[0] = "1"
for i in s:
    if n < 2:
        lis[int(i[0]) - 1] = str(i[-1])
    else:
        if lis[int(i[0]) - 1] != "0" and lis[int(i[0]) - 1] != str(i[-1]) and int(i[0]) - 1 != 0:
            print("-1")
            exit()
        if lis[0] == "0":
            print("-1")
            exit()
        lis[int(i[0]) - 1] = str(i[-1])

lis = int("".join(lis))
print(lis)