# problem C
N, M = map(int,input().split())

SC = []

for i in range(0,M):
    x = list(map(int,input().split()))
    SC.append(x)

if M != 0:
    suuji = [1]
else:
    suuji = [0]
suuji.extend([0]*(N-1))


hantei = 0

for i in SC:
    if (i[0] == 1) and (i[1] == 0) and (M != 0) and (N != 1):
        hantei = -1
        print(hantei)
        break
    else:
        pass

if hantei != -1:    
    for i in range(0,M):
        if hantei == -1:
            break
        else:
            for j in range(0,M):
                if SC[i][0] == SC[j][0]:
                    if SC[i][1] != SC[j][1]:
                        hantei = -1
                        print(hantei)
                        break
                    else:
                        pass
                else:
                    pass
else:
    pass
        
if hantei != -1:
        for i in SC:
            suuji[i[0]-1] = i[1]
        print(int(''.join(list(map(str,suuji)))))
else:
    pass