def main():
	# a = int(input())
	n,m = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	# l = [str(input()) for i in range(n)]
	#R行C列
	a = [list(map(int,input().split())) for x in range(m)]
	# print(' '.join(map(str,)))
	count = 0
	skip = 0
	dummy = []
	for i in range(10 ** (n-1),1000):
		# print("---")
		# print(i)
		temp = list(str(i))
		# print(temp)
		count = 0
		for x in range(m):
			# print("a[x][1] is {}".format(a[x][1]))
			# print("temp is {}".format(temp[a[x][0]-1]))
			if int(temp[a[x][0]-1]) == a[x][1]:
			# if temp[a[x][0]] == a[x][1]:
				count += 1
				# print("true")
				# print(count)
		if count == m:
			print(i)
			skip = 1
			break
	if skip == 0:
		print(-1)

if __name__ == '__main__':
	main()