import numpy as np

num_list = list(map(int, [i for i in input().split()]))
check_list = np.array([input().split() for i in range(num_list[1])])
check_list = np.array(list(map(list, set(list(map(tuple, check_list))))))

if len(check_list[:,0]) != len(set(check_list[:,0])):
    print(-1)
else:
    check_dict = dict(check_list)
    if check_dict['1'] == '0':
        print(-1)
    else:
        cnt = 0
        for i in range(num_list[0]):
            i+= 1
            i_s = str(i)
            cnt += int(check_dict.get(i_s, 0))*10**(num_list[0] - i)
        print(cnt)