line1 = input()
n, m = line1.split(" ")
n = int(n)
m = int(m)

num_list = ["a" for i in range(n)]

for i in range(m):
    line2 = input()
    s, c = line2.split(" ")
    s = int(s)
    if num_list[s-1] > c:
        num_list[s-1] = c

if n == 2 and num_list[0] == "a":
    print("-1")
elif n == 3 and num_list[0] == "a" and num_list[1] == "a":
    print("-1")
elif n == 3 and num_list[0] == "a":
    print("-1")
elif num_list[0] == "0":
    print("-1")
else:
    if "a" not in num_list:
        print("".join(num_list))
    else:
        num = "".join(num_list)
        num = num.replace("a","0")
        print(num)
        