n, m  = map(int, input().split())
result = ['10'] * n

for i in range(m):
    s, c = input().split()
    if int(c) < int(result[int(s)-1]):
        result[int(s)-1] = c
 
result = ['0' if i == '10' else i for i in result]
sentence = ''.join(result)
if sentence[0] == '0':
    print(-1)
else:
    print(int(sentence))
    
    