N, M = map(int, input().split())
SC = []
for i in range(M):
    SC.append(list(map(int, input().split())))
flag = 0
a = ""
A = [[] for row in range(N)]
for i, S in enumerate(SC):
    if not (str(S[1]) in A[S[0]-1]):
        A[S[0]-1].append(str(S[1]))
for i in range(0,N):
    if len(A[i]) == 0:
        if i == 0:
            a += "1"
        else:
            a += "0"
    elif i==0 and A[i][0] == "0":
        flag = 1
        break
    elif len(A[i]) == 1:
        a += A[i][0]
    else:
        flag = 1
        break

if flag == 1:
    print(-1)
else:
    print(int(a))