N,M=map(int,input().split())
A=[0 for i in range(N)]
B=[]
for i in range(M):
    tmp=list(map(int,input().split()))
    B.append(tmp)
    
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

C=get_unique_list(B)

for i in C:
    a=i[0]-1
    b=i[1]
    A[a]=b
    
ans=True
for i in range(len(C)):
    for j in range(1,len(C)):
        if C[i]==C[j]:
            ans=False
            
if A[0]==0:
    print(-1)
elif ans==False:
    print(-1)
else:
    print(*A,sep='')
