num = gets.split.map(&:to_i)
arr = []
ans = []
key = 0
zero = 0
tmp = 0
num[1].times do |i|
	arr[i] = gets.split.map(&:to_i)
	if arr[i] == [1, 0]
		zero = 1
	end
end
arr = arr.sort.uniq
len = arr.length

if num[0] != 1
	if zero == 1
		key = 1
	end
end
	
len.times do |i|
	len.times do |j|
		if arr[i][0] == arr[j][0] && arr[i][1] != arr[j][1]
			key = 1
		end
	end
end
	
num[0].times do |i|
	ans[i] = 0
end
len.times do |i|
	tmp = arr[i][0] - 1
	ans[tmp] = arr[i][1]
end
if ans[0] == 0
	ans[0] = 1
end

if key == 0
	puts ans.join('')
else
	p -1
end	