require "pry-byebug"

N,M = gets.split.map(&:to_i)
ary = []
M.times do |m|
  s,c = gets.split.map(&:to_i)
  ary << {s:s, c:c}
end
0.upto(1000) do |num|
  # N桁になっていない
  str = num.to_s
  digits = str.length
  next if digits != N
  found = true
  ary.each do |elm|
    s = elm[:s]
    c = elm[:c]
    #binding.pry if num == 702
    if digits < s
      found = false
      break
    end
    if str[s-1].to_i != c
      found = false
      break
    end
  end
  if found
    puts str
    exit
  end
end
puts "-1"