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) and hash[s] != c
    puts '-1'
    exit
  else
    str[s.to_i - 1] = c
    hash.store(s, c)
  end
end

if str[0] == '0' and str.size != 1
  puts '-1'
  exit
end

puts str
