n, m = map(int, input().split())
sc = [input().split() for _ in range(m)]

for x in range(10 ** (n - 1), 10 ** n):
    for s, c in sc:
        if str(x)[int(s) - 1] != c:
            break
    else:
        print(x)
        exit()
print(-1)