N,M=map(int,input().split())
s=[0]*M
c=[0]*M
for i in range(M):
    s[i],c[i]=map(int,input().split())
ans=[0 for i in range(N+1)]
if(N<max(s)):
    print('-1')
    exit()

else:
    for i in range(M-1):
        if(ans[s[i]]==0):
            ans[s[i]]=c[i]
        for j in range(i+1,M):
            if(s[i]==s[j]):
                if(c[i]!=c[j]):
                    print('-1')
                    exit()


an=0
for i in range(1,N+1):
    if(ans[i]==0):
        pass
    else:
        an=ans[i]*10**(N-i)+an
if(ans[1]==0):
    print('-1')
    exit()
if(an<=0):
    print('-1')
    exit()
print(an)
