n,m = map(int, input().split())
sc = list(tuple(map(int, input().split())) for _ in range(m))
sc = set(sc)



ans = [0]*n
cor = [0]*n
for s,c in list(sc):
    s = s-1
    ans[s] = c
    cor[s] += 1

for s,c in list(sc):
    s = s-1
    if cor[s] > 1:
        print(-1)
        exit()
if ans[0] == 0:
    print(-1)
    exit()

j = 0
for a in range(n):
    j += ans[a]*(10**(n-1-a))

print(j)