# coding:utf-8

N, M = map(int, input().split(' '))
ans = ['-1' for _ in range(N)]
for _ in range(M):
    s, c = input().split(' ')
    if ans[int(s)-1] == '-1':
        ans[int(s)-1] = c
    elif ans[int(s)-1] == c:
        pass
    else:
        print('-1')
        exit(0)

if ans[0] == '0' and len(ans) != 1:
    print('-1')
    exit(0)

print(ans)
output = ''
for el in ans:
    if output == '' and el == '-1':
        output += '1'
    elif el == '-1':
        output += '0'
    else:
        output += el
print(output)
