N,M = map(int,input().split())
S=[]
C=[]
for i in range(M):
    s,c = map(int,input().split())
    S.append(s)
    C.append(c)

ans = 0
C_check = []
S_check = []
for i in range(M):
    j = (N-S[i])
    if S[i] in S_check:
        index = S_check.index(S[i])
        if C[i]!=C[index]:
            ans = '-1'
            break
        continue
    if S[i] < N:
        if S[i]==1 and C[i]==0:
            ans = '-1'
            break
    ans += 10**j*C[i]
    S_check.append(S[i])





print(ans)
