N, M = [int(i) for i in input().split()]

guess_dict = dict()

flag = True
for i in range(M):
    s, c = [int(i) for i in input().split()]
    if s in guess_dict.keys():
        if c == guess_dict[s]:
            pass
        else :
            flag = False 
            break
    else :
        guess_dict[s] = c

if flag :
    guess_num = 0
    for k, v in guess_dict.items():
        guess_num += v * (10 ** (N-k))
        
    if len(str(guess_num)) == N:
        print(guess_num)
    else :
        print(-1)
else :
    print(-1)
    