#C - Guess The Number
N, M = map(int, input().split())
s =[list(map(int, input().split())) for i in range(M)]

s = list(map(list, set(map(tuple, s))))
s.sort(key=lambda x: x[0])
#print(s)
ans = [0 for a in range(3)]
ans2 = str("")
t_b = [1 for a in range(3)]
tmp_a = 0 #桁

for i in range(len(s)):
    if ans[s[i][0]-1] == 0:
        if s[i][1] > 0:
            ans[s[i][0] - 1] = s[i][1]
            tmp_a = s[i][0]
    else:
        print(-1)
        exit()

if ans[3-tmp_a] == 0:
    print(-1)
    exit()
else:
    for l in range(tmp_a):
        ans2 += str(ans[l])

print(int(ans2))