def solve():

    n,m = [int(i) for i in input().split()]
    
    
    s = [-1 for _ in range(m)]
    c = [-1 for _ in range(m)]
    
    for i in range(m):
        s[i],c[i] = [int(j) for j in input().split()]
    
    res = [-1 for _ in range(n)]
    
    for i in range(m):
        if(s[i] == 1 and c[i] == 0 and n != 1):
            print(-1)
            return
        
        elif(res[s[i]-1] == -1 or res[s[i]-1] == c[i]):
            res[s[i]-1] = c[i]
            
        else:
            print(-1)
            return
    
    
    if(res[0] == 0 and n!=1):
        res[0] = 1
    
    if(res[0] == 0 and n==1):
        print(0)
        return
    
    for i in range(n):
        if(res[i] == -1):
            res[i] = 0
    
    
    res = [str(_a) for _a in res]
    res = "".join(res)
    print(res)

if __name__ == "__main__":
    solve()