n, m = gets.split.map(&:to_i)
lists = []
m.times do
  lists << gets.split.map(&:to_i)
end
flag = true
num_lists = Array.new(m)
lists.each do |input|
  if num_lists[input[0] - 1].nil?
    num_lists[input[0] - 1] = input[1]
  else
    next if num_lists[input[0] - 1] == input[1]
    flag = false
    break
  end
end
num_lists = num_lists.map{|i| i ? i : 0}
if flag
  puts num_lists[0] == 0 ? -1 : num_lists.join('')
else
  puts -1
end
