N,M=map(int,input().split())
S=list()
C=list()
for i in range(M):
    t0,t1=map(int, input().split())
    S.append(t0)
    C.append(t1)
ans = 0
N0 = N
if M < N0:
    N0 = M
for i in range(N0):
    if (S[i] == 1) & (C[i] == 0):
        ans = -1

D = [0, 0, 0]
for i in range(M):
    if D[(S[i]-1)] == 0:
        D[(S[i]-1)] = C[i]
    elif D[(S[i]-1)] != C[i]:
        ans = -1
D0 = 100*D[0]+10*D[1]+D[2]
if ans != -1:
    print(D0)
else:
    print(ans)