# coding:utf-8

N, M = map(int, input().split(' '))
ans = ['-1' for _ in range(N)]
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(' ')
        try:
            if ans[int(s)-1] == '-1':
                ans[int(s)-1] = c
            elif ans[int(s)-1] == c:
                pass
            else:
                print('-1')
                exit(0)
        except IndexError:
            print('-1')
            exit(0)

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