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

ans1 = 0
ans2 = 0
ans3 = 0


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


ans = -1
if (flag==0):
    if ((N==3)and(ans1!=0)):
        ans = 100*ans1 + 10*ans2 + ans3
    elif ((N==3)and(ans1==0)):
        ans = 100 + 10*ans2 + ans3
    elif ((N==2)and(ans2!=0)and(flag1==0)):
        ans = 10*ans2 + ans3
    elif ((N==2)and(ans2==0)and(flag1==0)):
        ans = 10 + ans3
    elif((N==1)and(flag1==0)and(flag2==0)):
        ans = ans3

print(ans)