N,M=map(int,input().split())
a=[list(map(int,input().split())) for i in range(M)]
ans=0
for i in range(M):
    if ans==-1:
        break
    for j in range(M):
        if a[i][0]==a[j][0] and a[i][1]!=a[j][1]:
            ans=-1
            break
#print(ans)####      
answer=[0]*N
for i in range(M):
    answer[a[i][0]-1]=a[i][1]
    
if answer[0]==0:
    ans=-1
#print(answer)######
if ans==-1:
    print(ans)
else:
    ans=0
    for i in range(N):
        ans+=answer[i]*(10**(N-i-1))
    print(ans)