number = input().split(" ")
N = int(number[0])
M = int(number[1])
ans = ["○"]*N
a = 0
b = 0
for i in range(M):
    sc = input().split(" ")
    s = int(sc[0])
    c = int(sc[1])
    if ans[s-1] == "○":
        ans[s-1] = c
    elif ans[s-1] == c:
        pass
    else:
        a += 1
    if s == 1:
        b += 1
    else:
        pass

for i in ans:
    if i == "○":
        x = ans.index("○")
        ans[x] = 0

if M > 0:
    if b == 0:
        ans[0] = 1
    else:
        pass

if N > 1:
    if ans[0] == 0:
        a += 1
    else:
        pass

if a > 0:
    print(-1)
else:
    for i in ans:
        print(i,end="")