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

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

for i in range(m):
    s,c = map(int, input().split())
    if flg == 1 and int(r[s-1]) < c:
        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 r[0] == '0':
    print('-1')
else:
    print(''.join(r))

