n, m = map(int, input().split())
SC = [tuple(map(int, input().split())) for i in range(m)]
if n == 1:
	r = range(0, 10)
elif n == 2:
	r = range(10, 100)
else:
	r = range(100, 1000)
for i in r:
	si = str(i)
	for s, c in SC:
		if si[s-1] != str(c):
			break
	else:
		print(i)
		exit()
else:
	print(-1)