n,m=(int(x) for x in input().split())
dic={}
result=True
answer=0

for num_m in range(m):
    s,c=(int(x) for x in input().split())
    if s in dic.keys():
        if  c != dic[s]:
            result=False
    else:
        dic[s]=c
            
if 1 in dic.keys() and n!=1 and dic[1] == 0:
    result=False
    
if result:
    if 1 in dic.keys():
        answer+=dic[1]*(10**(n-1))
    else:
        answer+=1*(10**(n-1))
        
    for num_n in range(2, n+1):
        if num_n in dic.keys():
            answer+=dic[num_n]*(10**(n-num_n))

if not answer:
    answer = -1
            
print(answer)