N, M = list(map(int, input().split()))

s_list = []
c_list = []
number_dict = {}
minus_flag = False
for i in range(M):
    s, c = list(map(int, input().split()))
    if s in number_dict:
        if number_dict[s] == c:
            number_dict[s] = c
        else:
            minus_flag = True
            break
    else:
        number_dict[s] = c

if minus_flag is True:
    print("-1")
elif 1 in number_dict.keys() and 2 in number_dict.keys() and 3 in number_dict.keys():
    print(str(number_dict[1]) + str(number_dict[2]) + str(number_dict[3]))
elif 1 in number_dict.keys() and 2 in number_dict.keys():
    print(str(number_dict[1]) + str(number_dict[2]) + str(0))
elif 1 in number_dict.keys() and 3 in number_dict.keys():
    print(str(number_dict[1]) + str(0) + str(number_dict[3]))
elif 2 in number_dict.keys() and 3 in number_dict.keys():
    print(str(1) + str(number_dict[2]) + str(number_dict[3]))
elif 1 in number_dict.keys():
    if number_dict[1] == 0:
        print("-1")
    else:
        print(str(number_dict[1]) + str(0) + str(0))
elif 2 in number_dict.keys():
    print(str(1) + str(number_dict[2]) + str(0))
elif 3 in number_dict.keys():
    print(str(1) + str(1) + str(number_dict[3]))