n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
ans = -1
for i in range(10**(n-1), 10**n):
    isAns = True
    for s, c in sc:
        isAns *= i//(10**(n-s)) % 10 == c
    if isAns:
        ans = i
        break
print(ans)