flag = 1
keta,n = map(int,input().split())
sc = []
for i in range(n):
    sc.append(list(map(int,input().split())))

ans = [None]*keta

for j in sc:
    if j[0] == 1 and j[1] == 0 and keta != 1:
        flag = 0
    elif keta == 1:
        ans[0] = j[0][1]
    else:
        try:
            if ans[j[0]-1] == None:
                ans[j[0]-1] = j[1]
            elif ans[j[0]-1] != None and ans[j[0]-1] != j[1]:
                flag = 0
        except:
            flag = 0
        
        
for k in range(len(ans)):
    if k == 0 and ans[0] == None:
        ans[0] = 1
    elif ans[k] == None:
        ans[k] = 0
            
ans_s = ""
for l in ans:
    ans_s += str(l)
    
if flag == 0:
    print("-1")        
else:
    print(ans_s)  