import sys
n,m = map(int,input().split())
num_list = ["a","a","a"]
for i in range(m):
    s,c = map(int,input().split())
    if num_list[s-1] == "a":
        num_list[s-1] = c
    elif num_list[s-1] == c:
        pass
    else:
        print("-1")
        sys.exit()
while "a" in num_list:
    if num_list[0] == "a":
        num_list[0] = 1
    num_list[num_list.index("a")] = 0
if num_list[0] == 0:
    print("-1")
    sys.exit()
print(100*num_list[0]+10*num_list[1]+num_list[2])