n,m = map(int,input().split())
ans = [0]*n

for i in range(m):
    a,b = map(int,input().split())
    if a == 1 and b == 0:
        print(-1)
        exit()
    if ans[a-1] == 0:
        ans[a-1] = b
    else:
        if b != ans[a-1]:
            print(-1)
            exit()
if ans[0] == 0:
    ans[0] = 1
print(*ans,sep="")
