n,m=map(int,input().split())
seq=[list(map(int,input().split())) for  _ in range(m)]



count=0
while(True):
    flg=1
    for i in range(m):
#         print()
        s,c=seq[i]
        keta=len(str(count))
        if keta<n:
            flg=0
#             print("ttttt")
            break
        k=str(count)
        s-=1
        if int(k[s])!=c:
            flg=0
    if flg==1:
        break
    count+=1
    if count==1000:
        break
if flg==1:
    if (count==0)and(n!=1):
        print(-1)
    else:
        print(count)
else:
    print(-1)