n, m = gets.split.map(&:to_i)
k = Array.new(n, 0)
m.times {
  s, c = gets.split.map(&:to_i)
  if k[s-1] != 0 && k[s-1] != c
    puts -1
    exit
  end
  k[s-1] = c
}
if n > 1 && k[0] == 0
  puts -1
else
  puts k.join('')
end
