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