n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]

ans = ["x"] * n

for s, c in sc:
    if ans[s - 1] == "x":
        ans[s - 1] = str(c)
    else:
        if ans[s - 1] != str(c):
            print(-1)
            exit()

if n == 0:
    for i in range(10):
        i_2 = list(str(i))
        flag = True
        for j in range(len(i_2)):
            if ans[j] == "x":
                continue
            if i_2[j] != ans[j]:
                flag = False
        if flag:
            print(i)
            exit()
else:
    for i in range(10 ** (n - 1), 10 ** n):
        i_2 = list(str(i))
        flag = True
        for j in range(len(i_2)):
            if ans[j] == "x":
                continue
            if i_2[j] != ans[j]:
                flag = False
        if flag:
            print(i)
            exit()

print(-1)