N,M=map(int,input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
a=str(0)*N
A=[a[i] for i in range(len(a))]

#print(sc)
b=[]
c=[]
for i in range(M):
    if N==1:
        if (sc[i][0] == 1) and (sc[i][1]==0):
            a=-1
            break
        elif (sc[i][0]) in b:
            if sc[i][1]<int(A):
                A=str(sc[i][1])
        else:
            A[sc[i][0]-1]=str(sc[i][1])
            b.append(sc[i][0])
        c.append(sc[i][1])
    elif (sc[i][0] == 1) and (sc[i][1]==0):
        a=-1
        break
    else:
        if (sc[i][0]) in b:
            if sc[i][1]<int(A[sc[i][0]-1]):
                A[sc[i][0]-1]=str(sc[i][1])
        else:
            A[sc[i][0]-1]=str(sc[i][1])
            b.append(sc[i][0])
        c.append(sc[i][1])
        
if b==[]:
    a=-1
    print(a)
elif (1 not in b):
    a=-1
    print(a)
else:
    a="".join(A)
    print(a)