def main():
	n, m = map(int, input().split())
	s_l = []
	for _ in range(m):
		s, c = map(int, input().split())
		s_l += [(s - 1, c)]

	for i in range(10**(n - 1), 10**4):
		num = str(i)
		for s, c in s_l:
			if num[s] != str(c):
				break
		else:
			print(num)
			return 0
	if n == 1:
		num = '0'
		for s, c in s_l:
			if num[s] != str(c):
				break
		else:
			print(num)
			return 0
	print(-1)


main()
