# C - Guess The Number
N,M = map(int,input().split())
ans = [0]+[1]+[0]*(N-1)
check = [0]*(N+1)
for _ in range(M):
    s,c = map(int,input().split())
    if N>1 and s==1 and c==0:
        ans = -1
        break
    elif check[s]==0:
        ans[s] = c
        check[s] = 1
    elif ans[s]!=c:
        ans = -1
        break
if ans!=-1:
    ans = ''.join([str(x) for x in ans[1:]])
print(int(ans))