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 D.count(1) == 1:
    unko = C.index(1)
if len(D) <len(S) or Q[unko][1] == 0:
    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:
        print(sum1 + 10 ** n)