box, th = gets.chomp.split(' ').map(&:to_i) if th == 0 || th > box puts 0 else if box % 2 == 1 && th == (box.to_f / 2).round puts box - 1 else puts box - 2 end end