N,M=map(int,input().split())
wh=[None for _ in range(N)]
ans=0
for i in range(M):
    s,c=map(int,input().split())
    if wh[s-1] == None:
        wh[s-1]=c
        ans+=c*(10**(N-s))
    elif wh[s-1] == c :
        continue
    else :
        ans=-1
        break
if wh[0] == 0:
    ans=-1
print(ans)