n,m = map(int,input().split())
s=[]
v=[]
for _ in range(m):
    i,j=map(int,input().split())
    if i in s and j!=v[s.index(i)]:
        print(-1)
        exit()
    s.append(i)
    v.append(j)

if n>1 and (1 not in s or v[s.index(1)]==0) :
    print(-1)
    
j=0
for i in range(1,n+1):
    if i in s:
        j+=10**(n-i)*v[s.index(i)]
        
        
print(j)