
n, m = gets.chop.split.map(&:to_i)
hash = Hash.new(0)
a = true
m.times {
  a, b = gets.chop.split.map(&:to_i)
  if hash[a] != 0 && hash[a] != b
    a = false
  end
  if a == 1 && b == 0
    a = false
  end
  hash[a] = b
}
if !a
  print '-1'
elsif hash.max{ |(_key0,value0),(_key1,value1)| _key0<=>_key1 }[0] > n
  print '-1'
else
  sum = 0
  if hash[1] == 0
    hash[1] = 1
  end
  hash.each {|key, value|
    row = key - 1
    new_base = 100
    row.times {
      new_base = new_base/10
    }
    sum += (value * new_base)
  }
  print sum
end