n, k = gets.chomp.split.map(&:to_i) if k == 0 || k > n puts 0 elsif k % 2 == 0 || n % 2 == 0 puts n - 2 else puts n - 1 end