N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

d = {}

for s, c in sc:
    if s in d:
        if d[s] != c:
            print(-1)
            exit()
        else:
            continue
    d[s] = c

ans = 0
for i in range(1, N+1):
    if i in d:
        if (i == 1) & (d[i] == 0) & (N > 1):
            print(-1)
            exit()
        ans += d[i] * (10 ** (N - i))
    else:
        if i == 1:
            ans += 10 ** (N - i)
print(ans)