N, K = gets.split.map(&:to_i) if K < 1 || K > N p 0 elsif K + K-1 == N p N - 1 else p N - 2 end