N,M = map(int,input().split())
 
m = []
for i in range(M):
    m.append(list(map(int,input().split())))
for i in range(10**N):
    a = str(i)
    
    for j in range(M):
        try:
            
            if a[m[j][0]-1] == str(m[j][1]):
                True
            
            else:
                break
        except:
            break
            
        if j == M-1:
            if i > 10**(N-1)-1:
                print(i)
                exit()
            
print(-1)