n, m = map(int, input().split())
num = ["A"] * n
for i in range(m):
    s, c = map(int, input().split())
    if n == 1 and s == 1 and c == 0:
        print(0)
        exit()
    elif s == 1 and c == 0:
        print(-1)
        exit()
    elif num[s-1] == "A":
        num[s-1] = c
    elif num[s-1] != "A" and num[s-1] != c:
        print(-1)
        exit()
for j in range(3):
    if num[j] == "A":
        num[j] = 0
    if num[0] == 0:
        num[0] = 1
print(int("".join(map(str, num))))
