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 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:
    ans = 10 ** (n - 1)
elif ans == -1 or a[0] == 0:
    ans = -1
else:
    for i in range(n):
        ans += a[i] * 10 **(n - i - 1)
print(ans)
