N, M = map(int, input().split())
ans = [0] * N
for _ in range(M):
	s, v = map(int, input().split())
	i = s - 1
	if N != 1 and i == 0 and v == 0:
		print(-1)
		break
	elif ans[i] and ans[i] != v:
		print(-1)
		break
	ans[i] = v
else:
	if ans[0] == 0:
		ans[0] = 1
	print(*ans, sep='')
