n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

if n == 1:
    num_list = list(range(10))
else:
    num_list = list(range(10**(n-1), 10**n))
        
for i in num_list:
    for j, (s, c) in enumerate(sc, 1):
        if str(i)[s-1] != str(c):
            break
        if j == m:
            print(i)
            exit()
print(-1)