N, M = map(int, input().split())

s = [0] * M
c = [0] * M

for i in range(M):
    s[i], c[i] = map(int, input().split())

# print(10 ** N)

for i in range(10**(N-1), 10**N  ):
    tmp = 0
    x = str(i)
    for j in range(0,M):
        if x[(s[j] - 1)] == str(c[j]):
            tmp += 1
        else:
            break
    if tmp == N:
        print(i)
        break
else:
    print(-1)
