N, M = list(map(int, input().split()))

l = [0 for _ in range(N)]

flg = True
for _ in range(M):
    i, n = list(map(int, input().split()))
    if sum(l[:i-1]) == 0 and n == 0 and i != N:
        flg = False
    l[i-1] = max(l[i-1], n)

if not flg:
    print(-1)
else:
    res = 0
    l.reverse()
    for i in range(N):
        res += l[i] * 10**(i)
    print(res)