n, m = gets.split.map(&:to_i)
table = Array.new(m+1, -1)
m.times do
  conds = gets.split.map(&:to_i)
  if conds[0] == 1 && conds[1] == 0 && n != 1
    puts -1
    exit
  end
  if table[conds[0]] == -1
    table[conds[0]] = conds[1]
  elsif table[conds[0]] != conds[1]
    puts -1
    exit
  end
end
puts table[1..m+1].map{|ele| ele = ele == -1 ? 0 : ele }.join