N , M =map(int,input())

keta_list=[]
num_list=[]
for x in range(M):
    s,c =map(int,input().split())
    keta_list.append(s)
    num_list.append(c)
siteilist=[0]*N
siteilist[0]=1
errer =0
apperlist =[]

for i,x in enumerate(keta_list):
    siteilist[x-1]=num_list[i]
    if x == 1 and num_list[i]==0:
        errer= 1
    if x in apperlist:
        z =[]
        z = [l for l,i in enumerate(keta_list) if x == i ]
        if len(z)!=0:
            firest = num_list[z[0]]
            for b in z:
                if num_list[b] != firest:
                    errer = 1
                    
    apperlist.append(x)
out =0
if errer ==1:
    out =-1
else:
    for x in range(N):
        out += siteilist[x]*10**(N-x-1)
print(out)