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):
    digit -= 1
    if not res[digit] == 0:
        if res[digit] <= number:
            res[digit] = numer
        else:
            continue
    res[digit] = number

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