n,m=map(int,input().split())
x=[]
for _ in range(n):
    x.append([])

for _ in range(m):
    s,c=map(int,input().split())
    x[s-1].append(c)
ans=''
for i in range(n):
    if len(set(x[i]))>=2:
        ans='-1'
        break
    elif len(x[i])==0 and i==0:
        ans+='1'
    elif len(x[i])==0 and i!=0:
        ans+='0'
    else:
        if x[i][0]==0 and n==1:
            ans='0'
            break
        elif x[i][0]==0 and n!=1:
            ans='-1'
            break
        ans+=str(x[i][0])