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

ans = [-1] * n
for s,c in sc:
    if(ans[s-1] != -1):
        if(ans[s-1] != c):
            print(-1)
            exit()

    ans[s-1] = c

ans_num = 0
for i,num in enumerate(ans):
    if(num == -1):
        continue
    if(ans_num==0)&(num==0)&(i!=n-1):
        print(-1)
        exit()
    ans_num += num * 10**(2-i)

print(ans_num)