# ABC157 C - Guess The Number

n,m = map(int,input().split())
S=[]
C=[]
for i in range(1,m+1):
    s,c = map(int,input().split())
    S.append(s)
    C.append(c)
T_1=0
T_2=0
T_3=0
for p in range(m):
        for k in range(j+1,m):
            if S[j] == S[k]:
                if C[j] != C[k]:
                    print('-1')
                    exit()
        if S[p] ==1:
            T_1 =C[p]
        elif S[p] ==2:
            T_2 =C[p]
        elif S[p] ==3:
            T_3 =C[p]
if T_1 ==0:
    T_1 =""
if T_1 ==0 and T_2==0:
    T_2=""
T_T = str(T_1)+str(T_2)+str(T_3)
print(T_T)