import sys
N, M = map(int, input().split(" "))
Field = [0 for i in range(N)]
count = 0
m = 0
for i in range(M):
    a, b = map(int, input().split(" "))
    a -=1
    if a == 0:
        m +=1
    if Field[a] != 0 and Field[a] != b:
        count+=1
    else:
        Field[a] = b
if N != 1:
    if m == 0 and count ==0:
        Field[0] == 1
        for i in Field:
            print(i, end="")
    elif Field[0] == 0 or count !=0:
        print(-1)
    else:
        for i in Field:
            print(i, end="")
else:
    print(Field[0])
