N,M=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(M)]
s=[sc[i][0] for i in range(M)]
c=[sc[i][1] for i in range(M)]
sc.sort()
if N==1:
    if 2 in s or 3 in s:
        ans=-1
    else:
        ans=sc[0][1]
if N==2:
    if 3 in s:
        ans=-1
    else:
        if sc[0][0]==1:
            for i in range(1,M):
                if sc[i][0]==2:
                    ans=sc[i][1]+sc[0][0]*10
            else:
                ans=sc[0][1]*10
if N==3:
    if sc[0][0]==1:
        for i in range(1,M):
            if sc[i][0]==2:
                for j in range(i,M):
                    if sc[j][0]==3:
                        ans=sc[0][1]*100+sc[i][1]*10+sc[j][1]
                else:
                    ans=sc[0][1]*100+sc[i][1]*10
        else:
            ans=sc[0][0]*100
print(ans)