hash = Hash.new(0)
hash[1] = "1"
uniq_hash = Hash.new([])
n, m = gets.chop.split.map(&:to_i)
m.times {
  s, c = gets.chop.split.map(&:to_i)
  hash[s] = "#{c}"
  uniq_hash[s] = uniq_hash[s] + [c]
}
if hash[1] == "0"
  print '-1'
else
  result = ""
  for i in 1..n
    if uniq_hash[i].uniq.count > 1
      print '-1'
      break
    end
    result = "#{result}#{hash[i]}"
  end
  print result.to_i
end