n,m = list(map(int, input().split()))

target = ['-1'] * n
success = True
for i in range(m):
    s,c = input().split()
    if target[int(s)-1] == '-1' or target[int(s)-1] == c:
        target[int(s)-1] = c
    else:
        success = False
        break

for i in range(len(target)):
    if target[i] == '-1':
        target[i] = '0'

if target[0] == '0' or len(target) != str(int(n)):
    success = False

if success:
    print(''.join(target))
else:
    print('-1')