n,m = (int(i) for i in input().split())
number = [0] * n
answer = 0
result = ""
for i in range(m):
	s,c = (int (i) for i in input().split())
	if number[s-1] == 0:
		if s == 1 and c == 0:
			answer = -1
			break
		else:
			number[s-1] = c
	elif number[s-1] != c:
		answer = -1
		break
if answer == -1:
	print(answer)
else:
	for i in range(n):
		result += str(number[i])
	print(result)