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 = []
	zero = 0
	n1max = []
	if n == 1:
		for i in range(m):
			if a[i][1] == 0:
				zero += 1
			else:
				n1max.append(a[i][1])
		if zero == m:
			print(0)
		elif sum(n1max)//a[0][1] == n1max[0]:
			print(n1max[0])
		else:
			print(-1)
	else:
		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 and skip > 0:
				print(i)
				skip = 1
				break
		if skip == 0:
			print(-1)

if __name__ == '__main__':
	main()