N,M=map(int, input().split())
S=[0]*N
ans=0
for m in range(M):
    s,c=map(int, input().split())
    if (S[s-1]==0) or (S[s-1]==c):
        S[s-1]=c
    else:
        ans=-1
    
if ans==-1:
    print(ans)
elif (sum(S)!=0) and (len(S)==N):
    print(''.join(map(str, S)))
elif (sum(S)==0) and (len(S)==1):
    print(0)
else:
    print(-1)