n,m = map(int,input().split())
ans_list = ["x"]*n
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" and n != 1:
    print(-1)
    exit()
if n == 3 and ans_list[1] == "0":
    ans_list[0] ="1"
for i in range(n):
    if ans_list[i] == "x":
        ans_list[i] = "0"
ans = ""
flag = "off"
for i in ans_list:
    if i != "0":
        flag = "on"
    if flag == "on":
        ans += i
if ans == "":
    ans = 0
print(ans)