N,M=map(int,input().split())
s=[]
c=[]
for i in range(M):
    a,b=map(int,input().split())
    s.append(a)
    c.append(b)
keta=10 if N==1 else 100 if N==2 else 1000
res=[10]*3
ans=-1
for i in range(keta//10,keta):
    st=str(i)
    t=1
    for j in range(M):
        if(st[s[j]-1]!=str(c[j])):
            t=0
            break
    if(t==1):
        ans=i
        break
print(ans)