import itertools

N, M = map(int, input().split())
s, c = [], []
for _ in range(M):
	ts,tc = map(int ,input().split())
	s.append(ts)
	c.append(tc)

ans = 10**10
for p in itertools.product(range(10), repeat=N):
	if p[0] == 0:
		continue


	cond = 0
	for i in range(M):
		ind = s[i]-1
		num = c[i]

		if p[ind] != num:
			cond = 1
			break

	if cond:
		continue
	else:
		ans = min(ans, int(''.join(list(map(str, p)))))

if ans == 10**10:
	print(-1)
else:
	print(ans)
