n,m = gets.chomp.split(" ").map(&:to_i)
sc_arr = m.times.map{gets.chomp.split(" ").map(&:to_i)}

arr = []
n.times do
  arr << 0
end


if m == 0 then
  if n == 1 then
    puts 0
    exit
  end
  arr[0] = 1
  puts arr.join("").to_i
  exit
end

hash = {}
sc_arr.each do |s, c|
  if hash[s] && hash[s] != c then
    puts "-1"
    exit
  end
  hash[s] = c
end

arr.each_with_index do |a, i|
  if hash[i+1] then
    arr[i] = hash[i+1]
  end
end

result = arr.join("").to_i
if result.to_s.length == n then
  puts result
else
  puts "-1"
end
