N,M=map(int,input().split(" "))

s=[]
for i in range(M):
    s.append(list(map(int,input().split(" "))))

s.sort()
#print(s)

numlist=[]
#numlist.append(s[0])
numnum=0
for i in range(9):
    numlist.append([0,0])
for i in range(M):
    for j in range(9):
        if(numlist[j][0]==s[i][0]):
            if(numlist[j][1]!=s[i][1]):
                print("-1")
                exit()
            #else:
    numlist[numnum][0]=s[i][0]
    numlist[numnum][1]=s[i][1]
    numnum+=1
                        

    
#print(numlist)

if(numlist[0][1]==0):
    print("-1")
    exit()

num=""
for i in range(M):
    if(numlist[i][0]==i+1):
        num+=str(numlist[i][1])
    else:
        num+="0"
        
print(num)
