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

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [[0 for j in range(2)] for i in range(X)]

for i in range(X):
    s,c=map(int,input().split())
    S[i][0]=s
    S[i][1]=c
    


for i in range(1000):
    tmp=str(i)
    nagasa=len(tmp)
    if nagasa==N:
        count=0
        for j in range(X):
            if int(tmp[S[j][0]-1])==S[j][1]:
                pass
            else:
                break
            count+=1
            if count==X:
                print(i)
                exit()

print(-1)
        
        
    
