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

digit = [-1 for i in range(N)]
for i in range(M):
    s, c = map(int, input().split(" "))
    if s > N:
        print(-1)
        exit()
    if digit[s-1] == -1 or digit[s-1] == c:
        digit[s-1] = c
    else:
        print(-1)
        exit()

if N > 1 and digit[0] == -1:
    digit[0] = 1
for i in range(1, N):
    if digit[i] == -1:
        digit[i] = 0

ans = 0
coef = 10 ** (N-1)
for i in range(N):
    if digit[i]:
        ans += digit[i] * coef
    coef //= 10

if ans < 100 and N == 3:
    ans = -1
if ans < 10 and N == 2:
    ans = -1

print(ans)