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

s = [0]*M
c = [0]*M
result = [0]*N
types = 'str'
for i in range(M):
    s[i], c[i] = map(int, input().split())
    result[s[i]-1] = c[i]
    if (s[i]==1)*(c[i]==0):
        types = 'int' 
    
for i in range(N):
    if s.count(i+1) >= 2:
        if set(c[s==i+1])>1:
            types = 'int'
    
if types=='str':
    results = ''
    for i in result:
        results += str(i)
    print(int(results))
        
else:
    print(-1)