# coding:utf-8

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

if ans[3-N] == '0':
    ans[3-N] = '1'
print(''.join(ans))