import sys

n,m=map(int,input().split())
sc={}
ans=""
for i in range(m):
    s,c=map(int,input().split())
    if s in sc:
        if c<sc[s]:
            sc[s]=c
    else:
        sc[s]=c
for i in range(n):
    if i+1 in sc:
        ans+=str(sc[i+1])
    elif i > 0:
        ans+="0"

ans=int(ans)
if ans==0 or len(str(ans))!=n:
    ans = -1
print(ans)