n, m = map(int, input().split())

s = [0] * m
c = [0] * m
a = [0] * n

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

for i in range(m):
    if s[i] == 1 and c[i] == 0:
        print(-1)
        exit()
    for j in range(i, m):
        if s[i] == s[j] and c[i] != c[j]:
            print(-1)
            exit()

for i in range(m):
    a[s[i]-1] = c[i]

if a[0] == 0:
    a[0] == 1

ans = ''

for i in range(n):
    ans += str(a[i])

print(int(ans))