n, m = gets.chomp.split(" ").map(&:to_i)
seiyaku = []
m.times do 
	seiyaku.push(gets.chomp.split(" ").map(&:to_i))
	seiyaku[-1][0] -= 1
end

ans = [-1] * n
seiyaku.each do |s|
	if ans[s[0]] != -1 && ans[s[0]] != s[1] then
		puts -1
		exit
	end
	ans[s[0]] = s[1]
end

left = 114514
ans.length.times do |a|
	if ans[a] != -1 then
		left = a
		break
	end
end

ngo = 0
(left..ans.length - 1).each do |i|
	ngo += [ans[i] * 10 ** (ans.length - i - 1), 0].max
end

puts ngo > 0 ? ngo : -1


