n,m = map(int,input().split())
L = ["ng"]*n

for i in range(m):
    a,b = map(int,input().split())
    a -=1
    if L[a] == "ng":
        L[a] = str(b)
        if n >1 and L[0] == "0":
            print(-1)
            exit()
    else:
        if L[a] != "ng":
            if L[a] != str(b):
                print(-1)
                exit()
if "ng" in L:
    for i in range(n):
        if L[i] == "ng":
            L[i] = "0"
print("".join(L))