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
flag = True

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

if flag:
    for i in range(N):
        if num[i] == -1:
            num[i] = 0

    num_int = int("".join(map(str, num)))

    if len(num) == len(str(num_int)):
        ans = num_int

print(ans)
