n,m = map(int,input().split())
ans_list = ["x"]*3
for i in range(m):
    a,b = map(int,input().split())
    b = str(b)
    #print(ans_list)
    if ans_list[a-1] != b and ans_list[a-1] != "x":
        print(-1)
        exit()
    else:
        ans_list[a-1] = b
if ans_list[0] == "0":
    print(-1)
    exit()
elif ans_list[0] == "x":
    if ans_list[1] == "0":
        ans_list[0] = "1"
    elif ans_list[1] == "x":
        ans_list[0] = ""
        ans_list[1] = ""
for i in range(3):
    if ans_list[i] == "x":
        ans_list[i] = "0"
print("".join(ans_list))