[N,M] = list(map(int,input().split()))
SC = []
for i in range(M):
    SC.append(list(map(int,input().split())))
output = -1

X = [0]*N
X[0] = 1
Y = [0]*N
flag = 0

for i in range(0,M):
    S = SC[i][0]
    C = SC[i][1]
    if (S-1==0)and(C==0):
        flag = 1
        break
    if (Y[S-1]==0)or((Y[S-1]==1)and(X[S-1]==C)):
        X[S-1] = C
        Y[S-1] = 1
    else:
        flag = 1
        break

if (N==1)and(M==0):
    print(0)
elif N==1:
    Y = SC[0][1]
    for j in range(1,M):
        if Y!=SC[j][1]:
            flag = 1
    if flag == 1:
        print(-1)
    else:
        print(Y)

elif flag ==1:
    print(output)
else:
    output = ""
    for i in range(N):
        output += str(X[i])
    print(output)