n, m = map(int, input().split())

A = []
B = []
for i in range(m):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0

for i in range(0, 100000):
    if len(str(i)) != n:
        continue
    else:
        s = str(i)
        for j in range(m):
            if int(s[A[j] - 1]) != B[j]:
                break
            if j == m - 1:
                ans = 1
        
        if ans == 1:
            break
if ans == 1:
    print(i)
else:
    print(-1)