n, m = gets.strip.split(' ').map{|e|e.to_i}
str = '0' * n

hash = Hash.new()
m.times do
  s, c = gets.strip.split(' ')
  if hash.include?(s)
    if hash[s] != c
      puts '-1'
      exit
    end
  else
    str[s.to_i - 1] = c
    hash.store(s, c)
  end
end

if str[0] == '0'
  puts '-1'
  exit
end

puts str
