import numpy as np

num_list = list(map(int, [i for i in input().split()]))
if num_list[1] == 0:
    print(10**(num_list[0] -1))
else:
    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.get('1') == '0':
            if num_list[0] == 1:
                print(0)
            else:
                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)
            if num_list[0] == len(str(cnt)):
                print(cnt)
            else:
                cnt+= 100
                print(cnt)