n, m = gets.split(" ").map(&:to_i)
s = {}
err = false
def set key, value
  s[key] ||= value
  if s[key] != value then
    err = true
  end
  if key > 2 then
    err = true
  end
end

case n
when 1
  set 2, 0
  set 1, 0
when 2
  set 2, 0
end

m.times do |i|
  x, y = gets.split(" ").map(&:to_i)
  set n-x, y
end

if err then
  puts "-1"
else
  puts s[2]*100 + s[1]*10 + s[0]
end