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

for i in range(10 ** (n - 1), 10 ** n):
    s = str(i)
    for j in sc:
        if s[j[0]-1] != str(j[1]):
            break
    else:
        print(i)
        break
else:
    print(-1)
