n,m=map(int,input().split())
s=[]
c=[]
ans=[-1]*n
a=0

for i in range(m):
    ss,cc=map(int,input().split())
    
    ss-=1
    
    if ss in s and cc not in c:
        a=-1
        break
        
    ans[ss]=cc
    
    s.append(ss)
    c.append(cc)


if ans[0]==0:
    a=-1
    
if ans[0]==-1:
    ans[0]=1
    
    
for i in range(n):
    if ans[i]==-1:
        ans[i]=0
   

if a != -1:
    a=0
    for i in range(n):
        a+=ans[i]*(10**(n-i-1))
    
  
print(a)