# ABC 157 C
list_s=[]
list_c=[]
Flag=0
N,M= map(int,input().split())
for i in range(M):
    s,c= map(int,input().split())
    list_s.append(s)
    list_c.append(c)
    if s in list_s:
        x=list_s.index(s)
        n=list_c[x]

        if n!=c:
            Flag=1

    if s > N:
        Flag=1

if 1 in list_s:
    in1=list_s.index(1)
    n1=list_c[in1]
    if n1==0:
        Flag=1
else :
    n1=1

if 2 in list_s:
    in2=list_s.index(2)
    n2=list_c[in2]
else :
    n2=0

if 3 in list_s:
    in3=list_s.index(3)
    n3=list_c[in3]
else :
    n3=0

if N==1 and n1==0:
    Flag=0
    
if Flag==0:
    if N==1:
        print(n1)
    if N==2:
        print(10*n1+n2)
    if N==3:
        print(100*n1+10*n2+n3)
else :
    print(-1)
