n,m = map(int, input().split())
def guess_num(n,m):
    number_cond = [-1]*n
    for i in range(m):
        s,c = map(int, input().split())
        s = s-1
        if number_cond[s] >= 0 and number_cond[s] != c:
            return -1
        number_cond[s] = c
    # print(number_cond)
    if number_cond[0] == 0:
        return -1
    if number_cond[0] < 0:
        number_cond[0] = 1
    ret = 0
    for i in range(n):
        num = max(0, number_cond[i])
        ret += num*(10**(n-i-1))
    return ret
print(guess_num(n,m))