p,q= input().split()
a,b =(int(p), int(q))
ans =''
num_list =[]
pare_list=[]
for i in range(b):
    c = map(int,input().split())
    pare_list.append(list(c))
    num_list.append(pare_list[i][0])

search_list = list(range(a*10**3))[10**(a-1):10**(a)]


ans_list=[]
for i in search_list:
    count = 0
    ans_str = str(i)
    
    for j in range(b):
        
        if pare_list[j][1]==int(ans_str[num_list[j]-1]):
            count +=1
        else:
            break
        
        if count == len(num_list):
            ans_list.append(i)
            break

if len(ans_list)>=1:
    print(ans_list[0])
else:
    if a == 1 and b ==0:
        print(0)
    elif a== 1 and pare_list[0][1]==0:
        print(0)
    else:
        print(-1)