def doit(n,m)
	0.upto(m-1) do |i|
		s, c = $a[i]
		s -= 1
		if $ans[s] == 0 then
			$ans[s] = c
		else
			if $ans[s] != c then return -1 end
		end
	end

	sum = 0
	f = true
	0.upto(n-1){|i| ($ans[i]!=0)&&(f=false)}
	if f then
		if n==1 then 
			return 0
		else
			return -1
		end

	end

	if $ans[0] == 0 then $ans[0] = 1 end

	0.upto(n-1) do |i|
		sum += $ans[i]*10**(n-i-1)
	end
	return sum
end

n, m = gets.chomp.split(" ").map{|e|e.to_i}
$a = []
m.times do
	$a << gets.chomp.split(" ").map{|e|e.to_i}
end
$ans = Array.new(n,0)

print(doit(n,m))