N,M = list(map(int, input().split()))
s = []
c = []
for i in range(M):
    inputs = list(map(int, input().split()))
    s.append(inputs[0])
    c.append(inputs[1])

res = [0 for i in range(N)]
for digit, number in zip(s,c):
    index = digit - 1
    if res[index] == 0:
        res[index] = number
    else:
        if res[index] >= number:
            res[index] = number
        else:
            pass

convert = list(map(str, res))
res = int("".join(convert))
if len(str(res)) == N:
    print(res)
else:
    print(-1)