n, m = map(int,input().split())                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                           
bs=[None]*n                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                           
for i in range(m):                                                                                                                                                                                                                                                                         
    a,b=map(int,input().split())                                                                                                                                                                                                                                                           
    a -= 1                                                                                                                                                                                                                                                                                 
    if bs[a] is not None and bs[a] != b:                                                                                                                                                                                                                                                   
        print(-1)                                                                                                                                                                                                                                                                          
        exit()                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                           
    bs[a] = b                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                           
if bs[0] == 0:                                                                                                                                                                                                                                                                             
    print(-1)                                                                                                                                                                                                                                                                              
else:                                                                                                                                                                                                                                                                                      
    bs[0] == 0                                                                                                                                                                                                                                                                             
    for i in range(len(bs)):                                                                                                                                                                                                                                                               
        if bs[i] is None:                                                                                                                                                                                                                                                                  
            bs[i] = 0                                                                                                                                                                                                                                                                      
    print(''.join(map(str, bs)))   