N, M = [int(n) for n in input().split()]

s = [None] * M
c = [None] * M

smax = 1
for i in range(M):
    s[i], c[i] = [int(n) for n in input().split()]
    if smax < s[i]:
        smax = s[i]

ans = -1
for k in range(10 ** (smax - 1), 10 ** N):
    check = True
    n = str(k)
    for i in range(M):
        if n[s[i] - 1] != str(c[i]):
            check = False
            break
    if check:
        ans = k
        break

print(ans)