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())
#
ans = 0
for j in range(m):
    if n != 1:
        if s[j] == 1 and c[j] == 0:
            ans = -1
        else:
            if a[s[j] - 1] == 0:
                a[s[j] - 1] = c[j]
            else:
                if a[s[j] - 1] != c[j]:
                    ans = -1
                    break

#

if m == 0:
    if n != 1 :
        ans = 10 ** (n - 1)
    else:
        ans = 0
elif ans != -1:
    if n != 1:
        if a[0] == 0:
            ans = 10 **(n - 1)
            for i in range(n):
                ans += a[i] * 10 **(n - i - 1)
            else:
                for i in range(n):
                    ans += a[i] * 10 **(n - i - 1)

print(ans)
