n, m = gets.chomp.split(" ").map(&:to_i)
seiyaku = []
min = 1145141919
m.times do 
	seiyaku.push(gets.chomp.split(" ").map(&:to_i))
	min = seiyaku[-1][0] if seiyaku[-1][0] < min 
end
(10**(n-min)..10**n).each do |i|
	flag = true
	seiyaku.each do |s|
		if i.to_s()[s[0]-1] != s[1].to_s then
			flag = false
		end
	end
	if flag then
		puts i
		exit
	end
end
puts "-1"