N,M=map(int,input().split(' '))
q = [tuple(map(int,input().split(' '))) for i in range(M)]
ans = ''
d =['' for i in range(N)]
for i in q:
    s,c=i[0]-1,i[1]
    if d[s]=='':
        d[s]=c
    elif d[s] != c:
        print(-1)
        exit()
if d[0]==(''or 0):
    print(-1)
    exit()
for i in d:
    if i=='':
        print(0,end='')
    else:
        print(i,end='')