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

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