N, M  = map(int, input().split())
li = []
for i in range(M):
    li.append(list(map(int, input().split())))

li2 = [-1 for i in range(5)]
flag = 0
for i in range(M):
    if li2[li[i][0]] == -1 or li2[li[i][0]] == li[i][1]:
        li2[li[i][0]] = li[i][1]
    else:
        flag = 1
        break
if li2[1] == 0 and N != 1:
    flag = 1
if flag == 1:
    print(-1)
else:
    for i in range(1, N+1):
        if i == 1:
            if li2[i] == -1:
                print(1, end="")
            else:
                print(li2[i], end="")
        else:
            if li2[i] == -1:
                print(0, end="")
            else:
                print(li2[i], end="")