N , M = (map(int , input().split()))
A = []
for i in range(M):
    A.append(list(map(int , input().split())))
d = {i+1 : 10 for i in range(N)}
for i in A:
    nnum = min(i[1],d[i[0]])
    d[i[0]] = nnum
for k , v in d.items():
    if v == 10:
        d[k] = 0
ans = ''
zero = ''
for i in d.values():
    ans += str(i)
    zero += '0'
if len(str(int(ans))) != len(ans) and ans != zero:
    aans = -1
else:
    aans = int(ans)
print(aans)
