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 N == 3:
    if minus_flag is True:
        print("-1")
        exit()
    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]))
        exit()
    elif 1 in number_dict.keys() and 2 in number_dict.keys():
        print(str(number_dict[1]) + str(number_dict[2]) + str(0))
        exit()
    elif 1 in number_dict.keys() and 3 in number_dict.keys():
        print(str(number_dict[1]) + str(0) + str(number_dict[3]))
        exit()
    elif 2 in number_dict.keys() and 3 in number_dict.keys():
        print(str(1) + str(number_dict[2]) + str(number_dict[3]))
        exit()
    elif 1 in number_dict.keys():
        if number_dict[1] == 0:
            print("-1")
            exit()
        else:
            print(str(number_dict[1]) + str(0) + str(0))
            exit()
    elif 2 in number_dict.keys():
        print(str(1) + str(number_dict[2]) + str(0))
        exit()
    elif 3 in number_dict.keys():
        print(str(1) + str(0) + str(number_dict[3]))
        exit()
if N == 2:
    if minus_flag is True:
        print("-1")
        exit()
    elif 1 in number_dict.keys() and 2 in number_dict.keys():
        print(str(number_dict[1]) + str(number_dict[2]))
        exit()
    elif 1 in number_dict.keys():
        if number_dict[1] == 0:
            print("-1")
            exit()
        else:
            print(str(number_dict[1]) + str(0))
            exit()
    elif 2 in number_dict.keys():
        print(str(1) + str(number_dict[2]))
        exit()
if N == 1:
    if minus_flag is True:
        print("-1")
        exit()
    elif 1 in number_dict.keys():
        print(str(number_dict[1]))
        exit()
