N, M = map(int, input().split())
num = ['a','a','a']
for i in range(M):
    s, c = map(int, input().split())
    if num[s-1] == 'a':
        num[s-1] = str(c)
    elif num[s-1] == str(c):
        continue
    else:
        num.append('B')

if num[0] == 'a':
    num[0] = '1'

if num[1] == 'a':
    num[1] = '0'

if num[2] == 'a':
    num[2] = '0'

print(''.join(num) if num[-1] != 'B' else -1)
        