N,M=[int(i) for i in input() .split()]
# 二次元配列を得られる
A = []
answer=[0]*M
for i in range(M):
    A.append(list(map(int,input().split())))
j=0
for i in range(M):
    if answer[int(A[i][0])-1] == 0:
        answer[int(A[i][0])-1] = int(A[i][1])
    elif answer[int(A[i][0])-1] == int(A[i][1]):
        answer[int(A[i][0])-1] = int(A[i][1])
    else:
        print(-1)
        j=j+1
        break
seisu=0
if j==0 and answer[0]==0:
    j=j+1
    print(-1)
if j==0:
    for i in range(M):
        seisu=answer[i]*(10**(M-i-1))+seisu
    print(seisu)
