import sys
num_len, count = list(map(int, input().split()))
ans = [0] * num_len
for _ in range(count):
	keta, n = list(map(int, input().split()))	
	try:
		if ans[keta-1] == 0 or ans[keta-1] == n:
			ans[keta-1] = n
		else:
			print(-1)
			sys.exit()

	except IndexError:
		print(-1)
		sys.exit()

ans = list(map(str, ans))
if len(str(int(''.join(ans)))) == num_len:
	print(int(''.join(ans)))
else:
	print(-1)