N, M = map(int, input().split())
exists = True
digits = [-1]*N

for i in range(M):
    s, c = map(int, input().split())
    if digits[s-1] == -1 or digits[s-1] == c:
        digits[s-1] = c
    else:
        exists = False
        break

ans = 0
digits = list(reversed(digits))
print(digits)
for i in range(N):
    if digits[i] == -1:
        if i == N-1:
            digits[i] = 1
        else:
            digits[i] = 0
    if i == N-1:
        if digits[i] == 0:
            exists = False
            break
        elif digits[i] == -1:
            digits[i] = 1
            ans += (10 ** i)*digits[i]
        else:
            ans += (10 ** i)*digits[i]
    else:
        ans += (10 ** i)*digits[i]

if exists:
    print(ans)
else:
    print(-1)
