n,m = gets.chomp.split(' ').map(&:to_i)
arys = []
m.times do
  arys << gets.chomp.split(' ').map(&:to_i)
end

arys = arys.uniq
hoge = arys.flatten.each_slice(1).map(&:last)

arys.each do |ary|
  if hoge.count(ary[0]) > 1
    puts -1
    exit
  end
end

strs = '~' * n
arys.each do |ary|
  hoge = strs[ary[0]-1]
  if hoge == '~'
    strs[ary[0]-1] = ary[1].to_s
    next
  end
  if hoge.to_i > ary[1]
    strs[ary[0]-1] = ary[1].to_s
  end
end

strs[0] = '1' if strs[0].to_s == '~' &&  strs.size > 1

val = strs.gsub(/~/, '0').to_i
if val.to_s.size == n
  puts val.to_i
else
  puts -1
end
