n,m=map(int,input().split())
l=[]
for i in range(m):
    s,c=map(int,input().split())
    l.append((s,c))

ans=0
for i in range(1,1000):
    k=str(i)
    cnt=0
    if len(k)==n:
        for j in range(m):
            if int(k[l[j][0]-1])==l[j][1]:
                cnt+=1
        if cnt==m:
            ans=i
            break
if ans==0:
    print(-1)
else:
    print(ans)