N,M= list(map(int, input().split()))
P = [list(map(int,input().split())) for i in range(M)]
Q = list(map(list, set(map(tuple, P))))
C = []
S = []
n = N -1
sum1 = 0
for s in range(len(Q)):
    C.append(Q[s][0])
for t in range(len(Q)):
    S.append(Q[t][1])
D = list(set(C))
if len(D) <len(S) :
    print("-1")
else:
    for u in range(len(Q)):
        sum1 = sum1 + Q[u][1]*(10 ** (N - Q[u][0]))
    if sum1 >= (10 ** n):
        print(sum1)
    else:
        if D.count(1) == 1:
            unko = C.index(1)
            if Q[unko][1] == 0:
                print("-1")
            else:
                sum2 = sum1 + 10 ** n
                if sum2 < 999:
                    print(sum2)
                else:
                    print("-1")
                
        else:
            sum2 = sum1 + 10 ** n
            if sum2 < 999:
                print(sum2)
            else:
                print("-1")
