N,M = map(int,input().split())
S = []
C = []
for i in range(M):
    temp1,temp2 = map(int,input().split())
    S.append(temp1)
    C.append(temp2)

Flag = True
temp = [-1,-1,-1]
for i in range(M):
    if S[i] == 1:
        if temp[0] == -1 or temp[0] == C[i]:
            temp[0] = C[i]
        else:
            Flag = False
    elif S[i] == 2:
        if temp[1] == -1 or temp[1] == C[i]:
            temp[1] = C[i]
        else:
            Flag = False
    elif S[i] == 3:
        if temp[2] == -1 or temp[2] == C[i]:
            temp[2] = C[i]
        else:
            Flag = False

a = ''
if Flag == False:
    print(-1)
elif temp[0] == 0 or temp[0] == -1 and temp[1] == 0:
    print(-1)
else:    
    for i in range(3):
        if temp[i] == -1 and a == '':
            next
        elif temp[i] == -1:
            a = a + '0'
        else:
            a = a + str(temp[i])
    print(int(a))