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

num = [-1] * N
s = [0] * M
c = [0] * M

for i in range(M):
    s[i], c[i] = map(int, input().split())

ans = -1
check = True

for i in range(M):
    j = s[i] - 1
    if num[j] == -1:
        num[j] = c[i]
    if num[j] != c[i]:
        check = False
        break

if check:
    for i in range(N):
        if num[i] == -1:
            if i == 0:
                num[i] = 1
            else:
                num[i] = 0
    num_int = int("".join(map(str, num)))
    if len(num) == len(str(num_int)):
        ans = num_int

if M == 0:
    if N == 1:
        ans = 0
    else:
        ans = -1

print(ans)
