import math

N, M = map(int, input().split())
exists = True
digits = [-1]*N
for i in range(M):
    s, c = map(int, input().split())
    if N > 1 and s == 1 and c == 0:
        exists = False
        break
    elif digits[s-1] == -1 or digits[s-1] == c:
        digits[s-1] = c
    else:
        exists = False
        break
if exists:
    ans = 0
    digits = list(reversed(digits))
    for i in range(N):
        if digits[i] == -1:
            if i == N - 1:
                digits[i] = 1
            else:
                digits[i] = 0
        ans += math.floor((10 ** i)*digits[i])
    print(ans)
else:
    print(-1)
