n,m=map(int,input().split())
a={}
k=0
for i in range(m):
    b,c=map(int,input().split())
    if b in a:
        if a[b]!=c:
            k+=1
            break
        else:
            continue
    else:
        a[b]=c
if k>0:
    print(-1)
else:
    e=[]
    d = sorted(list(a.items()), key=lambda x: x[0])
    i=1

    for key,val in d:
        if key==i:
            e.append(str(val))
            i+=1
        else:
            for i in range(key-i):
                e.append(str(0))
            e.append(str(val))
            i+=1
    print(''.join(e))



