n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

ans = [-1 for _ in range(n)]
for sci in sc:
	if ans[sci[0]-1] == -1:
		ans[sci[0]-1] = sci[1]
	elif ans[sci[0]-1] != sci[1]:
		print(-1)
		exit(0)

if ans[0] == 0 and n != 1:
	print(-1)
	exit(0)

ansint = 0
for i, a in enumerate(ans):
	ansint *= 10
	if a == -1:
		if i == 0:
			ans[i] = 1
		else:
			ans[i] = 0
	ansint += ans[i]

print(ansint)
