n,m=map(int,input().split())
s,c=[],[]
for i in range(m):
    S,C=map(int,input().split())
    s.append(S-1)
    c.append(str(C))
  
if n==3:
    st,ed=100,1000
elif n==2:
    st,ed=10,100
else:
    st,ed=1,10
ans=-1

for t in range(st,ed):
    t_=list(str(t)) 
    
    for j in range (m):
        if t_[s[j]]!=c[j]:
            break
            
    else:
        ans=t
        break
    
    
print(ans)
    