import sys

N, M = map(int, input().split())
a = [0] * M
b = [0] * M
for i in range(M):
    a[i], b[i] = map(int, input().split())

for i in range(10**N):
    for j in range(M):
        Number = str(i)

        if i < 10:
            Number = "@@" + Number

        elif i < 100:
            Number = "@" + Number

        if str(Number[a[j] - 1]) != str(b[j]) or len(str(i)) != N:
            break

        if j == M - 1:
            print(i)
            sys.exit()
            
print(-1)