
N, M = list(map(int, input().split()))
sol = [-1] * N
for i in range(M):
    s, c = list(map(int, input().split()))
    if sol[s-1] != -1 and sol[s-1] != c:
        print('-1')
        exit(0)
    sol[s-1] = c
if sol[0] == 0:
    print('-1')
    exit(0)
if sol[0] == -1:
    sol[0] = 1
for i in range(N):
    if sol[i] == -1:
        sol[i] = 0
ret = 0
for v in sol:
    ret *= 10
    ret += v
print(ret)
