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

d = [0]*N

ans = 0
for m in range(M):
    s, c = map(int, input().split())
    if d[s-1] != 0:
        if d[s-1] == c:
            continue
        else:
            ans = -1
            break
    else:
        ans += 10**(N-s)*c
        d[s-1] = c

if d[0]==0:
    ans = -1

print(ans)
