N, M = gets.split(' ').map(&:to_i)
h = Hash.new
S = []
C = []
1.upto M do
  s, c = gets.split(' ').map(&:to_i)
  if h.has_key?(s)
    old_c = h[s]
    if old_c > c
      h.store(s, c)
    end
  else
    h.store(s, c)
  end
end
r = ''
if !h.has_key?(1) || h[1] == 0
  puts -1
  exit
end
1.upto N do |i|
  if h.key? i
    r += h[i].to_s
  else
    r += '0'
  end
end

puts r.to_i
