# coding:utf-8

N, M = map(int, input().split(' '))

if M == 0:
    if N == 1:
        print('0')
    else:
        print('-1')

else:
    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 N > 1 and ans[0] == '0':
        print('-1')
        exit(0)

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