N,M = map(int,input().split())

memo = [0]*N

for i in range(M):
    s,c = map(int,input().split())
    if s==1 and c==0:
        print(-1)
        break
    elif memo[s-1]==0:
        memo[s-1]=c

    else:
        if not memo[s-1]==c:
            print(-1)
            break


else:
    if memo[0]==0:
        memo[0]=1
    
    counter = 0
    for iterration,k in enumerate(memo):
        counter += k*(10**(len(memo)-iterration-1))
    print(counter)