def judgement(s,c,n,m):
    for i in range(m):
        for j in range(m):
            if (s[i]==s[j] and c[i]!=c[j]) or (s[i]==1 and c[i]==0):
                return False
    return True

def num(m,n,c,s,x):
    for i in range(n):
        for j in range(m):
            if s[i]-1==j:
                x[j]=c[i]
                #print(m,n,c,s,x)
    #print(m,n,c,s,x)
    if x[0]==0:
        x[0]==1
    x="".join(map(str,x))
    print(x)

n,m=list(map(int,input().split()))
s=[0]*m
c=[0]*m
x=[0]*n
for i in range(m):
    a=list(map(int,input().split()))
    s[i]=a[0]
    c[i]=a[1]
for i in range(n):
    x[i]=0

r=judgement(s,c,n,m)
if (r==True):
    num(m,n,c,s,x)
else:
    print(-1)