N = int(input())
M = int(input())
s = []
val = 10**(N-1)
for _ in range(M):
    tmp = int(input())
    if tmp in s:
        print('-1')
        exit()
    else:
        s.append(tmp)
        val += int(input())*(10**(N-tmp))

if 1 in s:
    print(val-10**(N-1))
else:
    print(val)