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

guess_dict = {'100':[0], '10':[0], '1':[0]}

for i in range(M):
    s, c = [int(i) for i in input().split()]
    if s == 1:
        guess_dict['100'].append(c)
    elif s == 2:
        guess_dict['10'].append(c)
    elif s == 3:
        guess_dict['1'].append(c)
        
def dupeChecker(guess_dict):
    for k, v in guess_dict.items():
        if len(set(v)) >= 3:
            return False
        elif len(set(v)) == 2:
            guess_dict[k] = guess_dict[k][1]
        elif len(set(v)) == 1:
            guess_dict[k] = guess_dict[k][0]        
    return guess_dict

guess_dict = dupeChecker(guess_dict)

guess_num = 0
if guess_dict:
    guess_num += guess_dict['100'] * 100
    guess_num += guess_dict['10'] * 10
    guess_num += guess_dict['1']
    if len(str(guess_num)) == N:
        print(guess_num)
    else :
        print(-1)
else :
    print(-1)
