n,m=map(int, input().split())
r = []

for i in range(n):
    r.append(str(0))

if n != 1 and m == 0:
    print('-1')
    exit()

for i in range(m):
    s,c = map(int, input().split())
    if n == 1 and s == 1 and c == 0:
        print('0')
        exit()
    elif n > 1 and s == 1 and c == 0:
        print('-1')
        exit()

    if int(r[s-1]) == 0:
        r[s-1] = str(c)
    elif int(r[s-1]) == c:
        r[s-1] = str(c)
    else:
        print('-1')
        exit()

if n > 1 and r[0] == '0':
    r[0] = '1'
    print(''.join(r))
else:
    print(''.join(r))

