N,M = map(int, input().split())
num = []
out = 0

for n in range(N):
    num.append(-1)

for i in range(M):
    s,c = map(int, input().split())
    if num[s-1] == -1:
        num[s-1] = c
    elif num[s-1] != c:
        print(-1)
        exit()

for i in range(N):
    if num[i] == -1:
        num[i] = (1 if i == 0 else 0)

if N>1 and num[0] == 0:
    print(-1)
    exit()

for i in range(N):
    out += num[i]*(10**(N-i-1))

if out == 1:
    print(-1)
    exit()

print(out)