import sys

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

s = [0]*m
c = [0]*m

for i in range(m):
    s[i], c[i] = map(int, input().split())

flag = 0

if n == 1:
    x = 10
elif n == 2:
    x = 100
else:
    x = 1000

for i in range(x):
    flag = 0
    for j in range(m):
        if len(str(i)) == n and str(i)[s[j]-1] == str(c[j]):
            flag += 1
    if flag == m:
        print(i)
        sys.exit()
print(-1)