n, m = map(int, input().split())
rules = [list(map(int, input().split())) for _ in range(m)]


def get_ans():
    if m == 0:
        return(10**(n-1))
        
    for i in range(10**(n-1), 10**n-1):
        for j, rule in enumerate(rules):
            if int(str(i)[rule[0]-1]) == rule[1]:
                if j == len(rules)-1:
                    return(i)
                else:
                    continue
            else:
                break
                
    return(-1)
    
    
print(get_ans())