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,)))

	# print(n,m)
	# print(a)
	ans = []
	mujun = []
	for c in range(n):
		ans.append(0)
		mujun.append(0)
	# print(ans)
	#まずは矛盾をチェック
	skip = 0
	for i in range(m):
		# print(a[i][0])
		if ans[a[i][0]-1] == 0:
			# print("true")
			# print("a is {}".format(a[i][1]))
			ans[a[i][0]-1] = a[i][1]
		elif ans[a[i][0]-1] != 0 and ans[a[i][0]-1] != a[i][1]:
			skip = 1
			print(-1)
			break
	if skip != 1:
		print(int(''.join(map(str,ans))))


if __name__ == '__main__':
	main()