N,M=map(int,input().split())
l=[]
for i in range(N):
    l.append([i,10])

f=True
for _ in range(M):
    a,b=map(int,input().split())
    if a==1:
        if b<l[a-1][1] and b!=0:
            l[a-1][1] = b
    else:
        if b<l[a-1][1]:
            l[a-1][1]=b

if l[0][1]==10:
    print(-1)
else:
    for i in range(N):
        if l[i][1]==10:
            l[i][1]=0
        print(str(l[i][1]),end="")


        