N,M=map(int, input().split())
SC=[list(map(int, input().split())) for _ in range(M)]

a = [0]*N

for i in range(0,3):
    for s,c in SC:
        if i+1 == s:
            a[i] = c

#print(a)
s = int(str(a[0])+str(a[1])+str(a[2]))
#print(s)

for i in range(10**N):
    if len(str(s)) != N:
        break
    if i == s:
        print(i)
        exit()

print(-1)