def main
  digit, restriction_num = gets.chomp.split(' ').map(&:to_i)
  candidate_answer = Array.new(digit, nil) 
  
  restriction_num.times do |_i|
    idx, num = gets.chomp.split(' ').map(&:to_i)
    if candidate_answer[idx-1]
      raise 'Restric Error' if candidate_answer[idx-1] != num
    else
      candidate_answer[idx-1] = num
    end
  end

  candidate_answer.fill { |i| candidate_answer[i].to_i }

  raise if candidate_answer[0].zero?
    
  puts candidate_answer.join('').to_i
  
  rescue 
    puts '-1'
end

main