def check(list3,list1,n):
    if(len(list3)==0 and n==1):
        return 0
    for i in range(a[1]-1):
        if((list3[i][0]==list3[i+1][0] and list3[i][1]!=list3[i+1][1]) or (list3[i][0]==1 and list3[i][1]==0)):
            return -1
    for i in range(a[1]):
            list1[list3[i][0]-1]=list3[i][1]
    s=''
    for i in list1:
        s+=str(i)
    if(len(str(int(s)))==n):
        return int(s)
    else:
        return -1
a=list(map(int,input().strip().split()))[:2]
list1=[0]*a[0]
list3=[]
for i in range(a[1]):
    b=list(map(int,input().strip().split()))[:2]
    list3.append(b)
list3.sort()
k=check(list3,list1,a[0])
print(k)




