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