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

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


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

guess_num = 0
guess_num += guess_dict['100'][0] * 100
guess_num += guess_dict['10'][0] * 10
guess_num += guess_dict['1'][0]


if len(str(guess_num)) != N:
    flag = False

if flag:
    print(guess_num)
else :
    print('-1')