N,M = map(int,input().split())

ans1 = 0
ans2 = 0
ans3 = 0


flag = 0
for i in range(M):
    s,c= list(map(int,input().split()))
    if s == 1:
        if (ans1==0) or (ans1 == c):
            ans1 = c
        else:
            flag = 1
            break
    elif s == 2:
        if (ans2==0) or (ans2 == c):
            ans2 = c
        else:
            flag = 1
            break
    elif s == 3:
        if (ans3==0) or (ans3 == c):
            ans3 = c
        else:
            flag = 1
            break


ans = 100*ans1 + 10*ans2 + ans3 if (flag==0) and (((N==3)and(ans1!=0)) or ((N==2)and(ans1==0)and(ans2!=0)) or ((N==1)and(ans1==0)and(ans2==0))) else -1
print(ans)