N, M = list(map(int, input().split()))
s, c = [], []
for _ in range(M):
    si, ci = list(map(int, input().split()))
    s.append(si)
    c.append(ci)

if s == 1:
    rb, re = 1, 9
elif s == 2:
    rb, re = 10, 99
else:
    rb, re = 100, 999

ans = -1
for v in range(rb, re + 1):
    sv = "{}".format(v)
    lf = [int(sv[s[i] - 1]) == int(c[i]) for i in range(M)]
    if all(lf):
        ans = v
        break
    # print(sv, lf, all(lf))
    
print(ans)