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]
    
for i in range(N):
    if s.count(N+1) >= 2:
        if set(c[s==N+1])>1:
            types = 'int'
if s.count(0) >= 2:
    if set(c[s==0])>1:
        types = 'int'
    
if types=='str':
    results = ''
    for i in result:
        results += str(i)
    print(int(results))
        
else:
    print(-1)