n, m = map(int, input().split())

lis = []
for i in range(m):
    lis.append(list(map(int, input().split())))
    
ans = [0,0,0]
k = 0
out = []

for i in lis:
    if i[0] not in out:
        ans[int(i[0]-1)] = int(i[1])
        out.append(i[0])
    elif i[0] in out:
        k += 1

inte = ans[0] * 100 + ans[1]*10 + ans[2]
    
    
if inte > 0 and k== 0:
    print(inte)
else:
    print(-1)
