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

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

s.sort()

if(N==1 and s[0][0]==1):
    print(s[0][1])
    exit()
elif(N==1 and s[0][0]!=1):
    print(-1)
    exit()


numlist=[0,0,0]

for i in s:

    if(numlist[i[0]-1]!=0 and numlist[i[0]-1]!=i[1]):
        print(-1)
        exit()
    else:
        if(i[0]>N):
            print(-1)
            exit()
        numlist[i[0]-1]=i[1]

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

num=""
for i in range(N):
    num+=str(numlist[i])
    
print(num)
