N,M = list(map(int,input().split()))
A = ["x"] * N
for i in range(M):
    B = input().split()
    if A[int(B[0])-1] == B[1]:
        pass
    elif A[int(B[0])-1] == "x":
        A[int(B[0])-1] = B[1]
    else:
        print("-1")
        exit()
A = "".join(A)
A = A.replace("x","0")
B = int(A)
if A == str(B):
    if len(str(B)) == N:
        print(B)
    else:
        print("-1")
        exit()
else:
    print("-1")