n,m=map(int,input().split())

if n==3:
    mod=100
elif n==2:
    mod=10
else:
    mod=1

a=[]
for i in range(m):
    a.append(list(map(int,input().split())))


for i in range(m-1):
    for j in range(i+1,m):
        if a[i][0]==a[j][0]:
            if a[i][1]!=a[j][1]:
                print(-1)
                exit()

a.sort()
a1=10
a2=10
a3=10
for i in range(m):
    if a[i][0]==1:
        a1=min(a1,a[i][1])
    if a[i][0]==2:
        a2=min(a2,a[i][1])
    if a[i][0]==3:
        a3=min(a3,a[i][1])
ans=0
if a1!=10:
    ans+=a1*100
if a2!=10:
    ans+=a2*10
if a3!=10:
    ans+=a3


if ans==0:
    print(-1)
else:
    if n==2:
        ans=list(ans)
        for i in range(2):
            print(ans[i],end="")
    elif n==1:
        ans=list(ans)
        print(ans[0])
    else:
        print(ans)
