require 'prime' n, k = gets.split.map(&:to_i) p (2...n).map { |i| [i,n.gcd(i).prime_division.sum{_2},i.prime_division.reduce(1){_1*-~_2[1]}] }.select{_2>=k}.max_by{_3}[0]