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

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