n,m=map(int,input().split())
seq=[]
for i in range(n):
    seq.append(0)
s=[]
c=[]
for i in range(m):
    a,b=map(int,input().split())
    s.append(a)
    c.append(b)
check=0
for i in range(m):
    for j in range(i+1,m):
        if s[i]==s[j] and c[i]!=c[j]:
            check+=1
for i in range (m):
    if s[i]==1 and c[i]==0:
        check+=1
if check>0:
    print(-1)
else:
    for i in range(m):
        seq[s[i]-1]=c[i]
    if seq[0]==0 and n!=1:
        seq[0]=1
    num=0
    for i in range(n):
        num+=seq[i]*(10**(n-1-i))
    print(num)