N,M = map(int,input().split())

result = [0] * N

for m in range(M):
    s,c = map(int,input().split())
    if N>=2 and s == 1 and c == 0:
        print(-1)
        exit()
    if result[s-1] == 0:
        result[s-1] = c
    else:
        if result[s-1] == c:
            continue
        else:
            print(-1)
            exit()

if result[0]==0:
    result[0] = 1

a = ""
for i in result:
    a += str(i)
print(int(a))