N,M = map(int,input().split())
A = [0]*N
B = [0]*N
ans = 0
for i in range(M):
    s,c = map(int,input().split())
    if (B[s-1]==1 and A[s-1]!=c) or (s==1 and N>=2 and c == 0):
        ans = -1
        break
    else:
        B[s-1] = 1
        A[s-1] = c

if ans == 0:
    for i in range(1,N-1):
        if A[i] == 0 and B[i] == 1:
            A[i-1] = 1
            break
        if A[i] != 0 and B[i] == 1:
            break
    ans = str(A[N-1])
    for i in range(N-2,-1,-1):
        ans = str(A[i])+ans
    ans = int(ans)
print(ans)