n, m = map(int, input().split())
num = ["A"] * n
for i in range(m):
    s, c = map(int, input().split())
    if n>2 and 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()
if num == [0]:
    print(0)
    exit
else:
    for j in range(n):
        if num[j] == "A":
            num[j] = 0
        if num[0] == 0:
            num[0] = 1
    print(int("".join(map(str, num))))
