n,m = map(int, input().split())
lst = [None]*m
for i in range(m):
    s,c = map(int, input().split())
    lst[i] = [s,c]

pass_lst =[]
ans = "no"
if n==1:
    for i in range(0,10):
        cnt = 0
        for j in range(m):
            num = str(i)
            if num[lst[j][0]-1] == lst[j][1]:
                cnt += 1
            if cnt  == m:
                ans = "ok"
                pass_lst.append(i)
                break
elif n==2:  
    for i in range(10,100):
        cnt = 0
        for j in range(m):
            num = str(i)
            if num[lst[j][0]-1] == lst[j][1]:
                cnt += 1
            if cnt  == m:
                ans = "ok"
                pass_lst.append(i)
                break
elif n==3:  
    for i in range(100,1000):
        cnt = 0
        for j in range(m):
            num = str(i)
            if int(num[lst[j][0]-1]) == lst[j][1]:
                cnt += 1
            if cnt  == m:
                ans = "ok"
                pass_lst.append(i)
                #print(cnt)
                break       

if ans == "no":
    print("-1")
else:
    print(min(pass_lst))