n, m = map(int, input().split())
s_c = tuple(set(tuple(map(int, input().split())) for _ in range(m)))

ans = 0
for sc in s_c:
    if  (sc[0] == 1 and sc[1] == 0) or sc[0] > n:
        print('-1')
        exit()
    
    for s in s_c:
        if s[0] == sc[0] and s[1] != sc[1]:
            print('-1')
            exit()
    
    ans += pow(10, (n - sc[0])) * sc[1]

if ans < pow(10, n - 1):
    ans += pow(10, n - 1)
print(ans)