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