N,M=map(int,input().split())
S=[list(map(int,input().split())) for _ in range(M)]

ans=''

S_sorted=sorted(S)
#print(S_sorted)

for j in range(M-1):
    if S_sorted[j][0]==S_sorted[j+1][0] and S_sorted[j][1]!=S_sorted[j+1][1]:
        ans='-1'

if ans!='-1':
    if S_sorted[0][0]==1 and S_sorted[0][1]==0:
        if N==1:
            ans=0
        else:
            ans='-1'

R=[1]

if ans!='-1' and ans!=0:
    for _ in range(1,N):
        R.append(0)
    
    for k in range(M):
        R[S_sorted[k][0]-1]=S_sorted[k][1]
    
    for l in range(N):
        ans+=str(R[l])
        int(ans)

#print(R)


print(ans)