n,m = map(int,input().split())
s = [0] * m
c = [0] * m
a = [-1] * n
for i in range(m):
    s[i],c[i] = map(int,input().split())
#
ans = 0
if m == 0:
    if n == 1:
        ans = 0
    else:
        ans = 10 ** (n - 1)
elif n >= 2:
    for j in range(m):
            # 1桁目が0
            if s[j] == 1 and c[j] == 0:
                ans = -1
                break
            elif a[s[j] - 1] != -1 and a[s[j] - 1] != c[j]:
                ans = -1
                break
            else:
                a[s[j] - 1] = c[j]
    if ans != -1:
        for k in range(n):
            if a[k] != -1:
                ans += a[k] * 10 ** (n - k - 1)

elif n == 1 and m == 0:
    ans = 0
else:
    for j in range(m):
        if a[0] == -1:
            a[0] = c[j]
        elif a[0] != c[j]:
            ans = -1
            break
        ans = a[0]








print(ans)
