n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    S, C = map(int, input().split())
    s.append(S-1)
    c.append(str(C))

ans = -1

if n == 3:
    st, ed = 100, 1000
elif n == 2:
    st, ed = 10, 100
else:
    st, ed = -1, 9

for i in range(st, ed):
    t = list(str(i))
    for j in range(m):
        if t[s[j]] != c[j]:
            break
    else:
        ans = i
        break
print(ans)