n,m=map(int,input().split())
l=[0]*(n+1)
flag=True
for _ in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0:
        flag=False
        print(-1)
        break
    elif l[s]==0 or l[s]==c:
        if c==0:
            l[s]=-1
        else:
            l[s]=c
    elif l[s]==-1 and c==0:
        l[s]=-1
    else:
        flag=False
        print(-1)
        break
for i in range(1,n+1):
    if l[i]==-1:
        l[i]=0
if flag==True:
    if n==1:
        print(l[1])
    else:
        k=0
        for i in range(1,n+1):
            k+=l[i]*10**(n-i)
        if l[1]==0:
            print(k+10**(n-1))
        else:
            
            print(k)