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

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

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

else:
    for i in range(m):
        s,c = map(int, input().split())
        if flg[s-1] == 1 and int(r[s-1]) < c:
            tmp = 1
        elif s == 1 and c == 0:
            r[s-1] = r[s-1]
        else:
            r[s-1] = str(c)
            flg[s-1] = 1
    
    if n == 1 and r[0] == '0':
        print('0')
    elif tmp == 1:
        print('-1')
    elif r[0] == '0':
        print('-1')
    else:
        print(''.join(r))

